How to define form field prefix in ASP.NET MVC

后端 未结 1 1281
猫巷女王i
猫巷女王i 2021-01-01 17:10

I am attempting to render a composite ProductCatalog view in ASP.NET MVC. This requires that I render multiple Product views per page. Each produ

相关标签:
1条回答
  • 2021-01-01 17:25

    Yes, you can define a prefix for the controls inside your view based on the executing action, consider the following code that should be place in your GET action method:

    ViewData.TemplateInfo.HtmlFieldPrefix = "DESIRED_PREFIX";
    

    this will add the required prefix to your View controls, but in order to deal with them back when you post your page, you will need to redefine the prefix in the signature of your POST action as the following:

    public ActionResult Create([Bind(Prefix = "DESIRED_PREFIX")] YOUR_ENTITY model)
    

    Let me know if it worked, thanks.

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