I have a table with "Tasks" and it has a relationship to the "timeframe" table. ie: morning, noon, afternoon
But default the generated create.cshtml shows the id of the timeframe because that is the relationship. But I would like to see the meaningfull name instead .
interwandere...
Contributor
2693 Points
542 Posts
using child element in create page (front end gui)
Jul 14, 2012 01:35 PM|LINK
Hi,
Simple question for experienced mvc developers...
How do I go about on using a list of child objects of the model in a dropdownlist for creating a new parent object?
few tips are welcome!
.one of my (older) projects social tomorrow and
francesco ab...
All-Star
20912 Points
3279 Posts
Re: using child element in create page (front end gui)
Jul 14, 2012 02:54 PM|LINK
What do you mean with "for creating a new parent object"
Mvc Controls Toolkit | Data Moving Plug-in Videos
interwandere...
Contributor
2693 Points
542 Posts
Re: using child element in create page (front end gui)
Jul 14, 2012 05:56 PM|LINK
Hey fransesco,
first of all, thanks for your reply.
I have a table with "Tasks" and it has a relationship to the "timeframe" table. ie: morning, noon, afternoon
But default the generated create.cshtml shows the id of the timeframe because that is the relationship. But I would like to see the meaningfull name instead .
<div class="editor-field">
@Html.DropDownList("idTimeFrame", String.Empty)
@Html.ValidationMessageFor(model => model.idTimeFrame)
</div>
But What I would like to see...
<div class="editor-field">
@Html.DropDownList("TimeFrameName", String.Empty)
@Html.ValidationMessageFor(model => model.TimeFrames.TimeFrameName)
</div>
What is the correct syntax please? (Will definitely hit the thanks button !)
.one of my (older) projects social tomorrow and
francesco ab...
All-Star
20912 Points
3279 Posts
Re: using child element in create page (front end gui)
Jul 15, 2012 08:38 AM|LINK
First of all it is better to use the m=>m.prop syntax. Then :
@Html.DropDownListFor(m => m.idTimeFrame,
initialSelectedValue)
where the select list specify the list of all possible id display values pairs (idTimeFrame, nameTimeFrame)
see here for more details on the syntax: http://stackoverflow.com/questions/1297399/populating-asp-net-mvc-dropdownlist
Mvc Controls Toolkit | Data Moving Plug-in Videos
interwandere...
Contributor
2693 Points
542 Posts
Re: using child element in create page (front end gui)
Jul 15, 2012 11:12 AM|LINK
Thanks, You know any good books on this topic?
.one of my (older) projects social tomorrow and
francesco ab...
All-Star
20912 Points
3279 Posts
Re: using child element in create page (front end gui)
Jul 15, 2012 01:54 PM|LINK
just give a look to the official tutorials: http://www.asp.net/mvc
Mvc Controls Toolkit | Data Moving Plug-in Videos