Partial View with parametrized prefix for controls names

后端 未结 4 1014
情深已故
情深已故 2020-12-21 11:48

I have a BarEditor.ascx, that can be called from diffent places.

<%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl

        
4条回答
  •  无人及你
    2020-12-21 12:21

    Why not create a model for the view? Your view would then need to be a strongly typed view using the data class FormView.

    public class FormView
    {
        string Bar {get; set;}
        string Baz {get; set;}
    }
    

    Then in your view you can use

    <% Html.RenderPartial("BarEditor", Model.Bar); %>
    <% Html.RenderPartial("BarEditor", Model.Baz); %>

    Your controller becomes

    public ActionResult Update(FormView MyForm)
    {
        ... = MyForm.Bar;
    
        ... = MyForm.Baz;
    }
    

提交回复
热议问题