简体   繁体   English

如何在ASP.Net MVC3 Razor中呈现部分页面

[英]How to render partial Page in ASP.Net mvc3 Razor

In my ASP.net MVC3 Razor project .I have to implement partial Page inside a normal view page ,but enable only after the action calls.But both files are referencing a single view model. 在我的ASP.net MVC3 Razor项目中。我必须在常规视图页面内实现部分页面,但只能在操作调用后启用。但是两个文件都引用一个视图模型。 How to use partial page inside a View page. 如何在视图页面内使用部分页面。

Controller Code for Partial Page 部分页面的控制器代码

//View Customer Data Detailed
public ActionResult DetailedData(int CusId)
{
    var data = from c in cus.CusModelData
                where c.CusId == CusId
                select c;
    return View(data.ToList());

}

View Code 查看代码

<td>
    @* @Html.ActionLink("Edi", "Edit", new { id = item.CusId }) |*@
    @Html.ActionLink("Details", "DetailedData", new { CusId = item.CusId }) |
    @Html.ActionLink("Delete", "DeleteCustomer", new { CusId = item.CusId })
</td>

Controller Code for View Page 查看页面的控制器代码

[HttpPost]
public ActionResult ViewCutomerData(string Name)
{
    var data = from c in cus.CusModelData
                where c.Name.Contains(Name)
                select c;

    return View(data.ToList());
}

Right now i am using like this inside view page 现在我正在使用这样的内部视图页面

View Customer Data Details 查看客户数据详细信息

@(Html.Partial("DetailedData") @(Html.Partial( “DetailedData”)

But again it displaying the table data in the View page .But i want to display it only after the "Details" Link is clicked. 但是,它再次在“视图”页面中显示表数据。但是,我只想在单击“详细信息”链接后才显示它。

屏幕截图解释了我期望做什么

I would go with ajax call after link click something like: 链接单击后,我将使用ajax调用:

  1. User clicks on link 用户点击链接
  2. The ajax call is executed: 执行ajax调用:

     .get("/Details/DetailedData",{"CusId" : requestedId}, function (data) { $("#your-detail-container").html(data); }); 

This line: 这行:

$("#your-detail-container").html(data);

will fill your details container with the view (html). 将用视图(html)填充您的详细信息容器。

Would be better if DetailedData action would return PartialView, not the View something like: 如果DetailedData操作返回PartialView,而不是返回诸如以下的View,效果会更好:

public ActionResult DetailedData(int CusId)
{
    var data = from c in cus.CusModelData
            where c.CusId == CusId
            select c;

    return PartialView(data.ToList());
}

In answer to your comments: 在回答您的评论时:

I suggest to use 我建议使用

@Ajax.ActionLink 

instead 代替

@Html.ActionLink

Or just use anchor tag . 或者只使用锚标签。 Replace 更换

@(Html.Partial("DetailedData")) with <div id="detailed-data-container"></div>

and fill this container with get response like this: 并用以下响应填充该容器:

$(document).on("click",".detailsLink", function () {
        .get("/Details/DetailedData",{"CusId" : requestedId}, function (data) {
            $("#detailed-data-container").html(data);
        });
 });

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

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