我查看了大多数 ModelBinding 示例,但似乎无法收集到我要查找的内容。
我想要:
<%= Html.TextBox("User.FirstName") %>
<%= Html.TextBox("User.LastName") %>
在 post 上绑定到这个方法
public ActionResult Index(UserInputModel input) {}
用户输入模型在哪里
public class UserInputModel {
public string FirstName {get; set;}
public string LastName {get; set;}
}
约定是使用没有“InputModel”的类名,但我不想每次都用 BindAttribute 指定这个,即:
public ActionResult Index([Bind(Prefix="User")]UserInputModel input) {}
我尝试过覆盖 DefaultModelBinder,但似乎找不到合适的位置来注入这一点功能。