Asp.net mvc 2 自定义HTML帮助程序扩展中的Jquery从表单中选择值

Asp.net mvc 2 自定义HTML帮助程序扩展中的Jquery从表单中选择值,asp.net-mvc-2,Asp.net Mvc 2,我在Razor视图中使用了此自定义帮助程序 @Html.Link("OpenewWindow", Constants.Value, new { k = Constants.k, Staff_ID = LoginHelper.GetLoggedInUser() }, new { id = "mytag", target="_blank" }) 当我点击这个链接时,它会为我打开一个新窗口,其中的查询字符串ConstantValue/Constants?=someValue&Staff\u ID

我在Razor视图中使用了此自定义帮助程序

  @Html.Link("OpenewWindow", Constants.Value, new { k = Constants.k, Staff_ID = LoginHelper.GetLoggedInUser() }, new { id = "mytag", target="_blank" })
当我点击这个链接时,它会为我打开一个新窗口,其中的查询字符串
ConstantValue/Constants?=someValue&Staff\u ID=UserLoggedName.

我想在表单上选择单选按钮selected值,并在QueryString中传递选中的值

那么,我在哪里可以在自定义助手方法中使用Jquery函数从表单中选择值呢

自定义助手方法接受这种类型的aurgument

 public static IHtmlString Link(this HtmlHelper htmlHelper, string linkText, string baseUrl, object query, object htmlAttributes).

您可以使用javascript来实现这一点。例如,您可以订阅链接的
单击
事件,然后通过添加新的查询字符串参数打开弹出窗口:

$(function() {
    $('#id_of_link').click(function() {
        var url = this.href;
        if (url.indexOf('?') > -1) {
            url += '&';
        } else {
            url += '?';
        }

        // get the value of the radio button
        var value = $(':radio[name="name_of_your_radio_groups"]:checked').val();
        url += url + 'radiovalue=' + encodeURIComponent(value);
        window.open(url, 'newwindow');

        // cancel the default action
        return false;
    });
});
如果您不需要使用javascript,那么更干净的方法是使用表单而不是链接。这样,所选单选按钮的值将自动发送