【发布时间】:2011-02-23 18:33:50
【问题描述】:
我的主要观点是这样的:
指数
<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);
}
}
}
和这样的部分视图:
福: 酒吧: 福: 酒吧:我总是得到由控制器操作设置的值。我想在视图中设置值并传递给部分视图。我该怎么做?
【问题讨论】:
-
对此有任何解决方案/提示吗?
-
到目前为止你有什么?你能发布一些代码吗?
-
我有一个需要两个链接的视图。我有两个局部视图和一个模型类。
标签: asp.net-mvc ajax partial-views