2012-02-20 58 views
1

如何在用户单击搜索后显示结果时如何构造ASP.Net MVC页面?如何在返回结果时构造Asp.Net MVC页面

我有一个叫做Index.cshtml的视图。我有称为Filter.cshtml的部分视图,它具有过滤器值和一个搜索按钮。当我点击搜索按钮时,我想在筛选条件旁边显示结果。会发生什么情况是我的部分视图Results.cshtml在整个页面上显示。什么是这种情况下正确的页面结构,以同时显示我的过滤器值和我的结果。

Index.cshml

@{ 
    ViewBag.Title = "Index"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

@{ Html.RenderPartial("Filter"); } 
@{ Html.RenderPartial("Results"); } 

Results.cshtml

<div>This will be the results page that should be displayed next to the filter values</div> 

的Controler操作方法:

public PartialViewResult Search(HarvestFilter filter) 
    { 
     return PartialView("Results"); 
    } 

回答

0

你并不需要额外的<div />标记。您致电@Html.RenderPartial()将为您提供生成数据所需的DOM元素。

请记住,如果您要呈现局部视图,则必须让您的Action Method匹配您调用的名称(或使用属性反映否则)。换句话说,你有一个叫做Search()的Action方法,但是你得到的部分渲染看起来并不是你的Search() Action方法。