简体   繁体   English

在ASP.NET MVC中返回Clean PartialView

[英]Return Clean PartialView in asp.net mvc

,Hi all, ,大家好,

When ı start my project , project opens in menu partial view. 当ı启动我的项目时,项目会在菜单局部视图中打开。

Menu has Customer and Report 菜单有客户和报告

İf ı click to customer , customer page opens.Then if ı click to Report page , Report pages appears with Customer Page. 单击“单击客户”,将打开“客户”页面。然后,如果“单击”到“报告”页面,则将显示“报告”页面和“客户”页面。

I need to clean CustomerPartial if ı click to report in menu. 如果要在菜单中单击以进行报告,则需要清洁CustomerPartial。

I am using json, 我正在使用json,

My Report ActionResult 我的报告动作结果

public ActionResult ReportSearchPartial(MyModel model)
{
var stringView = RenderRazorViewToString("_ReportPartialView", model);
return Json(stringView, JsonRequestBehavior.AllowGet);
}

Sounds like the best way for your menu approach would be rendering a Menu.cshtml partial View in a section in each View, that contains a menu for the desired object (Customer or Report). 听起来,您的菜单方法最好的方法是在每个视图的一个部分中呈现一个Menu.cshtml部分视图,其中包含所需对象(客户或报表)的菜单。

Think about a folder structure like this: 考虑这样的文件夹结构:

  • Views 观看次数
    • Customer 顾客
      • Menu.cshtml Menu.cshtml
      • Index.cshtml Index.cshtml

In each customer view eg "Index" you can render your Menu Partial within a section like this: 在每个客户视图(例如“索引”)中,您可以在以下部分中呈现菜单部分:

@section Menu {
    @Html.Partial("Menu", ViewData)
}
<h1>Customer</h1>

If you have a lot of customer views, create a customer layout view that renders the menu section for customer. 如果您有很多客户视图,请创建一个客户布局视图,为客户呈现菜单部分。 I won't use Json where its not needed. 我不会在不需要的地方使用Json。 The Menu view could contain an Ajax search form if you want. 如果需要,“菜单”视图可以包含Ajax搜索表单。 Hope I got you right. 希望我说对了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM