Asp.net mvc 4 将参数传递给mvc中的局部视图以加载特定的db行

Asp.net mvc 4 将参数传递给mvc中的局部视图以加载特定的db行,asp.net-mvc-4,partial-views,Asp.net Mvc 4,Partial Views,我正在开发一个MVC4应用程序,我即将完成。我唯一的问题是,在用户填写的多页表单的末尾,我希望有一个摘要页面,显示他们输入的所有信息。我认为最简单的方法是使用局部视图显示他们输入数据的不同页面中的表单数据。表单上的每一页都会传递一个int参数,该参数表示他们填写的表单的数据库中的id号(用户需要该id才能登录,因此会提前通过电子邮件发送该id)。问题是,一旦表单完成并加载了摘要页面,主视图就会加载id参数(例如它的mysite.com/vendor/quotesummary/22),但我不知道如

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

在我的控制器中:

[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());
    }
在我引用的总结观点中,我有:

@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());
@model SourceMvc.DAL.QuotesViewModel
@{
ViewBag.Title=“QuoteSummary”;
}
报价摘要
@Html.Partial(“QuoteSummaryChildOne”,新的SourceMvc.DAL.QuotesViewModel());
@Html.Partial(“QuoteSummaryChildTwo”,新的SourceMvc.DAL.quoteViewModel());
正如我所说,我的QuoteSummary正在加载正确的id参数,即使在我能够将该参数传递给部分视图之前,这并不意味着什么

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

[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(int id = 0)
{

    return View(new QuotesViewModel(/* whatever info you need from id */));
}

[HttpGet]
[ChildActionOnly]
public ActionResult QuoteDataSummary(int id = 0)
{

    return View(new QuotesViewModel(/* whatever info you need from id */));
}
在您的视图中,假设您的QuotesViewModel具有Id属性

@model SourceMvc.DAL.QuotesViewModel
@{
    ViewBag.Title = "QuoteSummary";
 }

<h2>Quote Summary</h2>

@Html.Action("GenInfoSummary", Model.Id);
@Html.Action("QuoteDataSummary", Model.Id);
@model SourceMvc.DAL.QuotesViewModel
@{
ViewBag.Title=“QuoteSummary”;
}
报价摘要
@Action(“geninfo摘要”,Model.Id);
@Action(“QuoteDataSummary”,Model.Id);

能否在要渲染局部视图的视图中放置操作

@Html.Action("GenInfoSummary","Home")
让动作结果呈现这样的局部视图

[HttpGet]
[ChildActionOnly]
public ActionResult GenInfoSummary(int id = 0)
{

    return PartailView(new QuotesViewModel());
}

该值名称来自路由定义。这就是为什么您不能设置它,路由从URL中提取它,并且该值优先。您的问题的解决方案是按照建议在操作中重置它,或者调整路由定义。

1)您正在向您的partial传递一行,但似乎应该传递id。2)您没有使用子操作。为此,您应该进行类似于@Html.Action()LOL的调用!正如你发布的那样,我一直在思考最好的答案,但我能做的就是指出答案。其余的取决于OP;)@的确是达维亚。看起来我需要一些休息Hey ojhawkins,很抱歉花了这么长时间才回复你,但这是一个对我有效的解决方案,所以谢谢你的帮助。