的ValidationSummary不是局部视图出现 [英] ValidationSummary not appearing with Partial Views

查看:114
本文介绍了的ValidationSummary不是局部视图出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的问题:

我去一个网页,如:

/Auction/Details/37

和这个调用此操作方法:

and this calls this action method:

public ActionResult Details(int id)

在这个方法中的特定行是:

A particular line in this method is:

return View("DetailsLub", auction);

此视图包含这一行:

@Html.Action("BidOnAuction", new { auctionId = Model.Id })

调用该操作方法:

Which calls this action method:

public PartialViewResult BidOnAuction(int auctionId)

到目前为止好?

现在,我在BidOnAuction看来,whcih有一个按钮的形式。当我点击这个按钮,这个动作方法invloked:

Now, I have a form in the BidOnAuction view, whcih has a button. When I click on this button, this action method is invloked:

[HttpPost]
public ActionResult BidOnAuction(BidOnAuctionViewModel model)

该操作方法具有如下的catch语句:

This action method has a catch statement with the following lines:

ModelState.AddModelError(string.Empty, operation + @" Failure: " + message);
return RedirectToAction("Details", new { id = model.AuctionId });

现在,无论是DetailsLUB观点和看法BidOnAction包含此行:

Now, both the DetailsLUB view and the BidOnAction view contain this line:

@ Html.ValidationSummary(真)

@Html.ValidationSummary(true)

不过,问题是,从来都没有被显示在屏幕上。我在做什么错了?

But, the issue is that nothing ever gets printed to the screen. What am I doing wrong?

推荐答案

这行code的

return RedirectToAction("Details", new { id = model.AuctionId });

RedirectResult 类的实例。是一般用于重定向和不呈现视图。如果你想呈现的孩子行动统一到使用 @ Html.Action 父视图,你需要从孩子的行动回报来看,并不RedirectResult。甚至当没有孩子的行动是RedirectResult将无法正常工作。回到RedirectResult会导致浏览器发出新的,该操作的所有新的要求。和模型状态反正丢失。你应该做这样的事情。

Returns instance of RedirectResult class. That is generally used for redirections and does not render view. If you want to render child action into parent view using @Html.Action, you need to return view from that child action, not RedirectResult. And that RedirectResult will not work even when there's no child action. Returning RedirectResult causes browser to issue fresh, all new request to that action. And model state is lost anyways. You should do something like

try
{
    //some actions
    return RedirectResult("Details", new { id = model.AuctionId });
}
catch
{
    ModelState.AddModelError(string.Empty, operation + @" Failure: " + message);
    return View("Details", new { id = model.AuctionId });
}

这篇关于的ValidationSummary不是局部视图出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆