选择下拉菜单,我该去哪个@html.action路由探索长尾疑问?
- 内容介绍
- 文章标签
- 相关推荐
本文共计277个文字,预计阅读时间需要2分钟。
如何将dropdownlist选择的值作为@.action的路径值。在MVC3项目中,你可以使用以下代码动态调用`eventid`作为dropdownlist的选择值。
@Html.DropDownList(eventId, new SelectList(Model.Events, Id, Name), new { @value=@Url.Action(FirmPassForum, Conference, new { eventId=Model.EventId }) })
如何将dropdownlist选择的值称为@html.action路由值.我在我的MVC3剃须刀中使用以下代码.我必须动态调用’eventid’作为dropdownlist选择值.
@Html.Action("FirmPassForum", "Conference", new { eventId = 69 }) 你不能这样做,因为Html.Action助手在服务器上呈现,而下拉选择可能在客户端上改变.一种可能性是使用AJAX调用.因此,基本上您可以订阅下拉列表的.change()事件,并向某些控制器操作发送AJAX调用,该操作将返回部分视图并更新DOM.
首先将其放入容器中:
<div id="container"> @Html.Action("FirmPassForum", "Conference", new { eventId = 69 }) </div>
然后:
<script type="text/javascript"> $(function() { $('#id-of-your-dropdown').change(function() { var eventId = $(this).val(); $.ajax({ url: '@Url.Action("FirmPassForum", "Conference")', type: 'GET', data: { eventId: eventId }, cache: false, success: function(result) { $('#container').html(result); } }); }); }); </script>
要使用此功能,您的FirmPassForum操作不应使用[ChildActionOnly]属性进行修饰:
public ActionResult FirmPassForum(int eventId) { MyViewModel model = ... return PartialView(model); }
本文共计277个文字,预计阅读时间需要2分钟。
如何将dropdownlist选择的值作为@.action的路径值。在MVC3项目中,你可以使用以下代码动态调用`eventid`作为dropdownlist的选择值。
@Html.DropDownList(eventId, new SelectList(Model.Events, Id, Name), new { @value=@Url.Action(FirmPassForum, Conference, new { eventId=Model.EventId }) })
如何将dropdownlist选择的值称为@html.action路由值.我在我的MVC3剃须刀中使用以下代码.我必须动态调用’eventid’作为dropdownlist选择值.
@Html.Action("FirmPassForum", "Conference", new { eventId = 69 }) 你不能这样做,因为Html.Action助手在服务器上呈现,而下拉选择可能在客户端上改变.一种可能性是使用AJAX调用.因此,基本上您可以订阅下拉列表的.change()事件,并向某些控制器操作发送AJAX调用,该操作将返回部分视图并更新DOM.
首先将其放入容器中:
<div id="container"> @Html.Action("FirmPassForum", "Conference", new { eventId = 69 }) </div>
然后:
<script type="text/javascript"> $(function() { $('#id-of-your-dropdown').change(function() { var eventId = $(this).val(); $.ajax({ url: '@Url.Action("FirmPassForum", "Conference")', type: 'GET', data: { eventId: eventId }, cache: false, success: function(result) { $('#container').html(result); } }); }); }); </script>
要使用此功能,您的FirmPassForum操作不应使用[ChildActionOnly]属性进行修饰:
public ActionResult FirmPassForum(int eventId) { MyViewModel model = ... return PartialView(model); }

