
[英]How to post data to actionResult method using Ajax.ActionLink?
[英]how to send an obect using post to ActionResult
在这里,我有“ bookAppointment”对象,我正在将该对象重定向到另一个actionresult,但该对象的值却显示在url中,例如
但是我不想显示我需要显示的对象的值,直到此http:// localhost:54592 / ServiceConsumer / AppointmentStatusPage
这是我的代码:
return RedirectToActionPermanent("AppointmentStatusPage", "ServiceConsumer", new RouteValueDictionary(bookAppointment));
和我的行动结果:
public ActionResult AppointmentStatusPage(BookAppointment bookAppointment)
{
try
{
if (!string.IsNullOrEmpty(Session["UserID"].ToString()) && !string.IsNullOrEmpty(bookAppointment.TransactionStatus))
{
return View(bookAppointment);
}
else
return RedirectToAction("guestsearch", "Home");
}
catch(Exception ex)
{
return null;
}
}
您可以执行以下操作:
在您的第一个控制器中:
public ActionResult Index()
{
BookAppointment model = new BookAppointment() { TransactionStatus = "Passed" };
return View(model);
}
您的第一个观点:
@model BookAppointment
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("AppointmentStatusPage", "ServiceConsumer", FormMethod.Post))
{
<input id="btnGo" type="submit" class="btn btn-sm btn-info" value="Go" />
@Html.HiddenFor(model => model.TransactionStatus);
}
在第二个控制器中:
[HttpPost]
public ActionResult AppointmentStatusPage(BookAppointment bookAppointment)
{
try
{
if (!string.IsNullOrEmpty(Session["UserID"].ToString()) && !string.IsNullOrEmpty(bookAppointment.TransactionStatus))
{
return View(bookAppointment);
}
else
return RedirectToAction("guestsearch", "Home");
}
catch (Exception ex)
{
return null;
}
}
用户使用HttpVerb(即POST)装饰Action结果,如下所示:
[HttpPost]
public ActionResult Index(Object obj)
{
//Your code goes here...
}
有关完整的示例,请访问以下页面:
https://www.aspsnippets.com/Articles/ASPNet-MVC-Form-Submit-Post-example.aspx
希望这会有所帮助,如果解决方案正确,请将此标记为答案。
问候,
N包阿
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.