如何刷新DropDownList的值更改页面? [英] How to refresh a page on dropdownlist value change?

查看:199
本文介绍了如何刷新DropDownList的值更改页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共同的布局页的意见。此布局页包含一个下拉列表,其中显示可用的日期列表。我要的是重新加载该页面已经不仅改变​​了数据参数。控制器,动作和任何其他PARAMS应该从当前请求范围内以某种方式作出。

I've got a common layout page for views. This layout page contains a dropdown list, which shows the list of available dates. What I want is to reload this page having changed the data param only. The controller, action and any other params should be somehow taken from the current request context.

如果我想要做手工上的每个观点,我会说这将是等于

If I wanted to do it manually on every view, I'd say it would be equal to

@Html.ActionLink(
     "",                                        
     "I need to have current action name here", 
     new { date = "The Value of the chosen SelectListItem" });

我怎样才能做到这一点?或者是有什么不同的做法?

How can I achieve this? Or is there any different approach?

推荐答案

关于当前行动的信息在 RequestContext的可用,你可以直接访问它:

Information about current action is available in RequestContext, you could access it directly:

@Url.Action(ViewContext.RequestContext.RouteData.Values["action"], 
         new { date = "The Value of the chosen SelectListItem" });

在你的情况我会将该网址添加到选项数据属性,然后使用它与jQuery:

In your case I would add the url to option data attribute and then work with it with jQuery:

$('select#yourid').change(function() {
    document.location.href = $(this).find('option:selected').data('url'));
});​

如何获取关于DropDownList的变化数据属性中可以看到这个 FIDDLE

这篇关于如何刷新DropDownList的值更改页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆