Joh*_*ohn 2 c# asp.net-mvc asp.net-mvc-3
在POST功能中,如果数量包含'字母',我想重新加载GET.我已经尝试了return View();
并查看了return Redirect(returnUrl);
但是URL有太多的参数.我只是重新加载GET EDITDETAIL
[Authorize]
public ActionResult EditDetail(int id, string returnUrl)
{
var order = _orderService.GetOrder(id);
[HttpPost, ActionName("EditDetail"), Authorize]
public ActionResult EditDetailPOST(int customerId, int? orderId, List<string> productId, List<string> quantity, string returnUrl, string TargetDate)
{
QBCustomerRecord customer = _customerService.GetById(customerId);
if (customer == null)
{
throw new InvalidOperationException("The customer id is Invalid.");
}
bool quantityContainsLetter = quantity.Any(s => s.Any(Char.IsLetter));
if (quantityContainsLetter)
{
_notifier.Information(T("A letter has been entered for quantity. Please enter a number"));
return View();
}
Run Code Online (Sandbox Code Playgroud)
您需要调用RedirectToAction
return RedirectToAction("EditDetail", new { id = 23, returnUrl = "" });
执行GET版本EditDetail
.请原谅我,如果我的RouteValueCollection
设置错了,我在开会前很快就会做出这个答案!:)
编辑:
好的,我误解了你的要求.为了显示从GET调用中显示的EditDetail视图,您必须调用:
return View("EditDetail")
我假设这是视图的名称,因为您的代码缺少return
EditDetail的GET版本中的语句.
此外,对于POST方法,您可以这样做:
[HttpPost]
[Authorize]
public ActionResult EditDetail(int customerId, int? orderId, List<string> productId, List<string> quantity, string returnUrl, string TargetDate)
Run Code Online (Sandbox Code Playgroud)
由于该方法的签名与GET版本不同,因此可以使用相同的名称重载该方法.不需要ActionName
属性.如果你这样做,那么你可以打电话
return View();
在POST方法中,无需传递视图名称.
归档时间: |
|
查看次数: |
58 次 |
最近记录: |