我正在开发一个 mvc 4 应用程序,我即将完成。我遇到的唯一问题是在用户填写的多页表单的末尾,我想要一个摘要页面来显示他们输入的所有信息。我认为最简单的方法是通过使用部分 View 来显示来自他们输入数据的不同页面的表单数据。在表单的页面之间,传递了一个 int 参数,该参数表示他们正在填写的表单在数据库中的 ID 号(用户会提前通过电子邮件收到该 ID,因为他们需要它才能登录)。问题是,一旦表单完成并加载了摘要页面,主视图就会加载 id 参数(例如它的 mysite.com/vendor/quotesummary/22),但我不知道如何传递该参数,到局部 View ,以便加载正确的数据。所以这就是我的代码:

在我的 Controller 中:

[HttpGet] 
    public ActionResult QuoteSummary(int id = 0) 
    { 
        General_Info general_info = unitOfWork.General_Info_Repository.GetByID(id); 
        return View(new QuotesViewModel(general_info)); 
    } 
 
    [HttpGet] 
    [ChildActionOnly] 
    public ActionResult GenInfoSummary() 
    { 
 
        return View(new QuotesViewModel()); 
    } 
 
    [HttpGet] 
    [ChildActionOnly] 
    public ActionResult QuoteDataSummary() 
    { 
 
        return View(new QuotesViewModel()); 
    } 

然后在我的 QuoteSummary View 中我有:

@model SourceMvc.DAL.QuotesViewModel 
@{ 
    ViewBag.Title = "QuoteSummary"; 
 } 
 
<h2>Quote Summary</h2> 
 
@Html.Partial("QuoteSummaryChildOne", new SourceMvc.DAL.QuotesViewModel()); 
@Html.Partial("QuoteSummaryChildTwo", new SourceMvc.DAL.QuotesViewModel()); 

就像我说的,我的 QuoteSummary 正在加载正确的 id 参数,即使在我将该参数传递给部分 View 之前这没有任何意义。

两天来我一直在努力解决这个问题,我觉得答案必须很简单,这就是为什么它如此令人沮丧的原因。非常感谢你们能提供的任何帮助。

请您参考如下方法:

你能不能在要渲染局部 View 的 View 中放置一个 Action

@Html.Action("GenInfoSummary","Home") 

然后让操作结果呈现这样的局部 View

[HttpGet] 
[ChildActionOnly] 
public ActionResult GenInfoSummary(int id = 0) 
{ 
 
    return PartailView(new QuotesViewModel()); 
} 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!