MVC Controller parameter for a form element with a dot in it?

前端 未结 3 1936
孤城傲影
孤城傲影 2021-02-19 18:45

If you\'re using the Html.TextBoxFor() type methods, you may well end up with Form controls that have dots in their names, like this:

3条回答
  •  爱一瞬间的悲伤
    2021-02-19 19:11

    Depending on the other form controls, you should be able to have the MVC default model binder construct a Contact object for you. Then the signature of your action method would be:

    [HttpPost]
    public ActionResult FooAction(Contact contact)
    

    Then the Contact.FirstName (and any other fileds) will be bound correctly

提交回复
热议问题