c# - Controller returns null on submit @Html.BeginForm -


i have following form:

@model proj.viewmodels.addmenu @using(html.beginform()) {  @html.antiforgerytoken() @html.textboxfor(x=>x.menu.menuname) @html.textboxfor(x=>x.menuitem.menuitemname)    <input type="submit" /> } 

and viewmodel

public class addmenu {      public menu menu { get; set; }     public menuitem menuitem { get; set; } } 

a menu can have menuitem. when submit form, expected see addmenu model have menuname completed , addmenu.menuitem.menuitemname completed.

i going add menu item menu (as menu has collection of menuitems in it).

but both menu , menuitem addmenu come null?

does know why case?

the problem you're having here you're trying bind textboxes types aren't strings, dates, integers, etc. mvc doesn't know menu , menuitem class. in these classes?

what perhaps consider create viewmodel 2 string properties, named menu , menuitem. in case you'll have populated data in postback, after can want (map other objects, etc.)

this article contains answer seems quite complete me if you're interested in reading more.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -