我有這樣的主視圖:Ajax請求獲取局部視圖
<%@頁標題= 「」 語言= 「C#」 的MasterPageFile = 「〜/查看/共享/的Site.Master」 繼承=」 System.Web.Mvc.ViewPage」%>
指數
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<h2>
Index</h2>
<script type="text/javascript">
$(function() {
$('#mylink').click(function() {
$('#resultpartial1').load(this.href);
return false;
});
});
$(function() {
$('#mysecondlink').click(function() {
$('#resultpartial1').load(this.href, { id: 123 });
return false;
});
});
</script>
<%= Html.ActionLink("click me","Partial1","Foo",new MyViewModel { Foo = "123" , Bar="456" },new { id = "mylink" }) %>
<%= Html.ActionLink("click me second link","Partial2", "Foo", new { id = "123" }, new { id = "mysecondlink" }
)%>
和控制器是這樣的:
public class FooController : Controller
{
//
// GET: /Foo/
public ActionResult Index()
{
return View();
}
public ActionResult Partial1(string id)
{
// TODO: use the id to fetch the model from somewhere
MyViewModel model = new MyViewModel { Bar = "a", Foo = "1" };
return View(model);
}
public ActionResult Partial2(string id)
{
// TODO: use the id to fetch the model from somewhere
MyViewModel model = new MyViewModel { Bar = "b", Foo = "2" };
return View(model);
}
}
}
和局部視圖所示:
<%@控制語言= 「C#」 繼承= 「System.Web.Mvc.ViewUserControl」 % >
的Foo: 酒吧:<%@控制語言= 「C#」 繼承=「System.Web.Mvc.ViewUserControl 「%>
富: 酒吧:我總是得到通過控制器操作設定值。我想在視圖中設置值並傳遞到局部視圖。我怎樣才能做到這一點 ?
任何解決方案/提示此? – asif 2011-02-23 18:39:41
到目前爲止你有什麼?你可以發佈一些代碼嗎? – 2011-02-23 18:41:30
我有一個視圖,我需要兩個鏈接。我有兩個部分視圖和一個模型類。 – asif 2011-02-23 18:44:00