简体   繁体   English

如何将模型从用于模型的编辑器传递到控制器? (使用asp.net)

[英]How do you pass a model from Editor for model into a controller? (using asp.net)

@model mymodelsnamespace

    @using (Html.BeginForm("MyMethodName", "MyContollerName", FormMethod.Post)) 
    {
         @Html.EditorFor(m => Model, "Submit", new { multiple = true }) 
        <input type="submit" value="Submit" />
    }

I know the code I am going write will be close to whats above 我知道我要编写的代码将接近上面的代码

How do I passed the updated model into MyMethodName is i can continue to manipulate it in my controller? 我如何将更新的模型传递给MyMethodName,这样我才能继续在控制器中对其进行操作?

Please provide the signature for MyMethodName and the cshtml to give the model to the method in the controller. 请提供MyMethodName和cshtml的签名,以将模型提供给控制器中的方法。

If you add this code to your controller, it should work. 如果将此代码添加到控制器中,它将正常工作。

[HttpPost]
public ActionResult MyMethodName (YourModel model)
{
    ... some code here.

}

You may find the Model-View-ViewModel pattern interesting. 您可能会发现Model-View-ViewModel模式很有趣。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何对 ASP.NET Core 控制器或模型对象进行单元测试? - How do you unit test an ASP.NET Core controller or model object? 如何将模型传递回ASP.NET MVC中的Controller? - How do I pass Model back up to Controller in ASP.NET MVC? asp.net mvc如何将完整模型从视图传递到控制器 - asp.net mvc how to pass full model from view to controller 单击 ASP.NET MVC 中的按钮时,如何将 model 值从视图传递到 controller - How to pass model value from a view to a controller when clicking on the button in ASP.NET MVC 如何将自定义模型对象从剃刀视图传递到ASP.NET MVC 5中的控制器操作 - How to pass custom model object from razor view to controller action in ASP.NET MVC 5 如何使用相同的控制器但不同的动作将数据从一个视图传递到另一个视图? ASP.Net 和 Microsoft Graph - How do you pass data from one view to another using the same controller but different actions? ASP.Net & Microsoft Graph 如何将Enum从视图传递到模型ASP.Net MVC - How to pass Enum from view to model ASP.Net MVC ASP.NET MVC:如何将列表(从Model中的类)传递到View中的转发器? - ASP.NET MVC: How do I pass a list (from a class in Model) to a repeater in a View? C#-如何在ASP.NET MVC的HTML表单中传递内部带有其他模型的模型 - C# - How do I pass a model with another model inside from a HTML form in ASP.NET MVC How can you maintain model state in ASP.NET Core between repeatedly displaying the Model in a View and sending the model back to the Controller? - How can you maintain model state in ASP.NET Core between repeatedly displaying the Model in a View and sending the model back to the Controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM