PartialView调用控制器PartialViewResult。 [英] PartialView invoke controller PartialViewResult .
本文介绍了PartialView调用控制器PartialViewResult。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为所有页面的公共视图添加一个partialview(有一些数据库的数据)。
我这样做,当从其他视图渲染partialview然后不调用控制器PartialViewResult但是如果直接渲染则调用来自url(localhost / Home / partialviewName)。
代码如下:
I want to add a partialview(With some databse's datas) for common view to all page.
I did that, when partialview render from other view then not invoke controller PartialViewResult but invoke if direct render from url(localhost/Home/partialviewName).
code is bellow
This is controller
public PartialViewResult partial(Auction auc)
{
auc.Name = "Abhilash Kumar";
return PartialView("~/Views/Home/partial.cshtml",auc);
}
这是部分查看
This is partial View
@model MyMVC.Models.Auction
<div style="padding:10px 10px 10px 10px">
<p style="color:#ff0000">@Model.Name </p>
</div>
So how to invoke controller when partial view render from any other view.
推荐答案
如果要调用返回局部视图的操作结果,可以使用Html。 RenderAction()
通过以下链接。
MVC使用控制器操作渲染局部视图 [ ^ ]
If you want to call a action result which return a partial view you can use Html.RenderAction()
Go through the below link.
MVC Render Partial view with action from controller[^]
这篇关于PartialView调用控制器PartialViewResult。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文