Is there any good reason to use FormCollection instead of ViewModel?

前端 未结 11 1559
离开以前
离开以前 2020-11-27 15:09

I\'ve inherited a code base written in ASP.Net MVC 4. Every post method takes a FormCollection. Aside from annoyance of having to access the values through quot

11条回答
  •  眼角桃花
    2020-11-27 15:41

    Yes. Sometimes, it can be useful. Here's an example:

    Let's say we have in our db "date_and_time_field".

    In Razor View, we want to use two form fields. The first one "Date" (maybe with jQuery UI Datepicker). The second one "Hour".

    In the Controller Action, we compose the "date_and_time_field" by means of Request.Form["Date"] and Request.Form["Hour"].

    There are other scenarios where it can be useful:

    • A cross-table (with checkBoxes in Razor view)

    • The collection Request.Unvalidated().Form (maybe this is not part of your question: I don't wanna be off-topic)

提交回复
热议问题