ASP.NET MVC model bind ID mismatch -
I have a view in MVC 2 where I edit the page "Page" has a name, title and content. Content is editable content, which has width, CSS class and columns. The column is a list.
When I do this in the scene:
<% = Html.TextBoxFor (m => m.Name)%>
This produces the following HTML:
& lt; Input type = "text" value = "about page" name = "name" id = "name" & gt;
And when I edit the action in ContentController:
/// & lt; Summary & gt; /// Importing the specified forms /// & lt; / Summary & gt; /// & lt; Param name = "item" & gt; Content page & Lt; / Param & gt; /// & lt; Returns & gt; As a result for action & lt; / Returns & gt; [Http post] Edit Public Action Result (page item) {if (ModelState.IsValid) {} Return View (item); }
This name can not divide the property to the property. By looking at the values in the request. Form, I see the name parameter.
If I present the text box manually, then its use:
& lt;% = Html.TextBox ("ItemName", Model.Name )% & Gt;
The value is fully bound for the page instance in the controller action.
Am I doing something fundamentally wrong?
If your action method parameter is named item , the default model binder Item.name , item.title , item.content.width , etc. If he can not find any * item. ** In the request, this will ignore the item prefix and will return to the empty prefix, only name title , content. Width , etc.
There are some things in the request that item (or * ** **. **), which is not generating this fallback logic. If you want to emphasize fallback logic, then give the attribute to the parameter [bind (prefix = ""]], which says, "Yes, I know that this parameter was given the name of the item, but its The name of the play is in fact ". "
Comments
Post a Comment