在使用控制器动作两种不同的模式为POST和GET [英] Using two different Models in controller action for POST and GET
本文介绍了在使用控制器动作两种不同的模式为POST和GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在我的MVC项目控制器之一添加方法。在一个普通的GET我要回类型的强类型对象 CaseEditModel
和POST动词我想视图返回类型的对象案例
控制器。那可能吗?
I have "Add" method in one of my controllers in MVC project. On a normal "GET" I want to return Strongly-Typed object of type CaseEditModel
and on POST verb I want the view to return an object of type Case
to the controller. Is that possible?
推荐答案
是的,在得到您的添加操作可以返回CaseEditModel到视图和后的添加操作的类型可以是个案的说法。帖子上的模型绑定会尝试绑定到任何你把一个参数。
Yes, on a get your Add action can return CaseEditModel to the view and on a post the argument for the Add action can be of type Case. On the post the model binder will try and bind to whatever you put in for an argument.
[HttpGet]
public ActionResult Add()
{
var caseEdit = new CaseEditModel();
return View(caseEditModel);
}
[HttpPost]
public ActionResult Add(Case caseIn)
{
}
这篇关于在使用控制器动作两种不同的模式为POST和GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文