I am using MVC 3 final RTM.
Given
This route:
context.MapRoute(
"Blog_Posts",
"Blog/Posts/{id}/{slug}",
new { controller = "Posts", action = "Index", slug = UrlParameter.Optional }
);
And on a post's page, e.g. /blog/posts/2/some-slug I bind a partial view with a Comment
model:
@Html.Partial("_CommentEditor", new Comment())
And Comment
has a public int Id {get; set;}
.
And in the partial view, I have this:
@Html.HiddenFor(comment => comment.Id)
Why does it display this?
<input type="hidden" value="2" name="Id" id="Id" data-val-required="The Id field is required." data-val-number="The field Id must be a number." data-val="true">
And why when I change Id
on Comment
to CommentId
does it correctly have a value of 0
?
Me thinks the default model binder is binding to the {id}
of the route.