如何在asp.net mvc中渲染局部视图

问题描述:

Hi
我正在使用MVC Structure。我必须创建一个可以通过下拉过滤的报告。我是使用局部视图来显示报告的东西。

HEre是我想要实现的页面的结构。

在页面顶部,会有一些掉落下面的列表。

这些将是报告的页面。



当用户从下拉列表中更改选项时,报告将被过滤。



我有两个问题

1.如何渲染部分页面。

2.如何刷新部分页面通过ajax / jquery。我想在客户端这样做。



我在网上查了一下,我正在渲染页面,如下面的代码所示

**查看**



Hi I am using MVC Structure. I have to create a report which can be filtered by drop downs. I am thing to use a partial view to display report.
HEre is the structure of the page I want to achieve.
On top of page, there will be some drop down lists.
Below these will be page for report.

when user changes the options from dropdownlist, the report will be filtered.

I have two questions
1. How to render partial page.
2. How to refresh partial page through ajax/jquery. I want to do this on client side.

I have checked online, I am rendering page as shown in code below
**VIEW**

<h3>Report</h3>
<div>
    <table>
        <tr>
            <td>ServiceLine</td>
            <td>@Html.DropDownList("ServiceLine", null, new {id="ServiceLine"}) </td>
        </tr>
    </table>
</div>
<div>
    <h2>List</h2>
    <div>
        @Html.Partial("PartialView")
    </div>
</div>





这就是我在控制器中得到的东西





This is what I have got in controller

public ActionResult PortfolioReport(char serviceLine)
{
    //Department List

     var serviceLines = Enum.GetValues(typeof(SogetiDepartments)).Cast<SogetiDepartments>().Select(v => new SelectListItem
    {
        Text = v.ToString(),
        Value = ((char)v).ToString(),
    });

     foreach (SelectListItem item in serviceLines)
     {
         if (Convert.ToChar(item.Value) == serviceLine)
             item.Selected = true;
     }


     ViewBag.ServiceLine = serviceLines;

    return View();
}





感谢任何形式的帮助。



Any kind of help is appreciated.

我在ASP.NET MVC中编写了一篇关于使用Ajax将部分视图加载为部分视图结果的文章。请尝试以下链接

http://fromjamitoothers.blogspot.in/2013/03/load-partial-view-as-partial-view.html [ ^ ]

希望这可以帮助你
I have write an article about Load Partial View as Partial View Result using Ajax in ASP.NET MVC.Try the below link
http://fromjamitoothers.blogspot.in/2013/03/load-partial-view-as-partial-view.html[^]
Hope this helps you