[英]How to route from one controller action method to another controller action method without displaying controller name in MVC 5
[英]How to call one Action method from another Action method(both are in the same Controller) in MVC C#?
嗨,从调用操作方法中,我有:
[HttpPost]
public JsonResult SubmitForms(Note note, string action = "Submit")
{
//some code
RedirectToAction("SaveDemographicForm", "PatientForms", new { model.DemographicFormData, action="Submit" , submitAll = true });
//some code
}
这是我试图调用的操作方法:
[HttpPost]
public JsonResult SaveDemographicForm(DemographicForm demographicForm, string action = "Save", bool submitAll = false )
{
//Some code
}
我在这里做错了什么? 提前致谢。
如果它们都在同一个控制器中,您不需要重定向到操作,只需直接调用它。
[HttpPost]
public JsonResult SubmitForms(Note note, string action = "Submit")
{
//some code
return SaveDemographicForm(new DemographicForm { /*your properties*/ }, "Save", false);
}
[HttpPost]
public JsonResult SaveDemographicForm(DemographicForm demographicForm, string action = "Save", bool submitAll = false )
{
//return some json object
}
只打电话不回
[HttpPost]
public JsonResult SubmitForms(Note note, string action = "Submit")
{
SaveDemographicForm(new DemographicForm { /*your properties*/ }, "Save", false);
//somecode
//submitforms return
}
[HttpPost]
public JsonResult SaveDemographicForm(DemographicForm demographicForm, string action = "Save", bool submitAll = false )
{
//return some json object
}
RedirectToAction()
返回一个RedirectToRouteResult
:
public ActionResult AnotherAction(int id)
{
//Do something with the id ...
return View()
}
public RedirectToRouteResult DoAndRedirect()
{
//Do something and go to the desired view:
return RedirectToAction("AnotherAction", new { id = x.ID });
}
使用 System.Web.Mvc.Html;
public ActionResult Index() { HtmlHelper helper = new HtmlHelper(new ViewContext(ControllerContext, new WebFormView(ControllerContext, "Index"), new ViewDataDictionary(), new TempDataDictionary(), new System.IO.StringWriter()), new ViewPage()); helper.RenderAction("Index2");//call your action return View(); } public ActionResult Index2(/*your arg*/) { //your code return new EmptyResult(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.