ASP.Net MVC Postback a label value to your controller

后端 未结 1 1432
花落未央
花落未央 2021-01-05 02:57

When using an EditorTemplate, if I want a value on the model to be displayed on the screen, but also to be posted back to the controller, what helper should I use?

i

1条回答
  •  -上瘾入骨i
    2021-01-05 03:12

    @Html.DisplayTextFor(model => model.RoomTypeName)
    @Html.HiddenFor(model => model.RoomTypeName)
    

    This is very clean and standard way of doing what you want to achieve.

    If you would make your own HTML helper that does exactly the same thing it by saving one line would just confuse other people who might read your code in the future, or even yourself.

    0 讨论(0)
提交回复
热议问题