[英]Partial View Name in Ajax response
I have a controller that returns one of two partial view depending on condition. 我有一个控制器,根据情况返回两个局部视图之一。
Controller 调节器
public ActionResult ReviewCart(DepartmentProductViewModel model)
{
if(somecondition)
{
return PartialView("_View1", model);
}
return PartialView("_View2", model);
}
In my View I have Two tabs one for _View1 and other for _View2 with div tags. 在我的视图中,我有两个选项卡,一个用于_View1,另一个用于_View2,带有div标签。 Like Tab 1
像标签1
<div id="shopping1">
@Html.Partial("_View1", Model)
</div>
Tab 2 标签2
<div id="shopping2">
@Html.Partial("_View2", Model)
</div>
In my Ajax response I would like check the if controller is returning _View1 then I would like to 在我的Ajax响应中,我想检查控制器是否返回_View1,然后我想
$('#shopping1').html(data);
and if controller is returning _View2 then I would like to 如果控制器返回_View2,那么我想
$('#shopping2').html(data);
Any idea how to achieve this in Ajax success call. 任何想法如何在Ajax成功调用中实现这一目标。
Thanks 谢谢
If I understood correctly, this example might help. 如果我正确理解,此示例可能会有所帮助。
with help of jquery-ui tabs
借助
jquery-ui tabs
<script>
$( function() {
$("#tabs").tabs({
beforeLoad: function( event, ui ) {
ui.jqXHR.fail(function() {
ui.panel.html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
});
}
});
} );
</script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="@Url.Action('ReviewCart','Controller')">Partial Content 1</a></li>
<li><a href="@Url.Action('ReviewCart','Controller')">Partial Content 2</a></li>
</ul>
<div id="tabs-1">
</div>
</div>
You may need pass a parameter to distinct two partial views from each other to render and change the action method itself accordingly. 您可能需要传递参数以使彼此分开的两个局部视图相互关联,以相应地呈现和更改action方法本身。
Eg Url.Action('ReviewCart','Controller',new { view=1 })
例如
Url.Action('ReviewCart','Controller',new { view=1 })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.