本文介绍了使用JavaScript ASP.Net MVC 3.0 Ajax.ActionLink动态对象路径的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0项目

在我看来,我有一个隐藏的申请具有用户名。在一个动作中生成该用户ID(所以这不会知道前)

In my view I have a hidden filed which has a UserID. This user id is generated upon an action (so this will not be know prior)

在这个隐藏字段的值,我想用这个值作为一个ActionLink的routevalue。我可以用jQuery选择这样做。

Once this hidden field has a value, I would like to use that value as an actionlink routevalue. Can I do it with a jquery selector.

我的隐藏字段是

<input id="NewUserID" type="hidden" value="80">

我ajax.ActionLink是

My ajax.ActionLink is

@Ajax.ActionLink("Edit", "EditUser", "User", new { UserID = "$('#GetNewPatientID').val()" },
        new AjaxOptions
        {
            OnSuccess = "ShowEditUserForm",
            UpdateTargetId = "EditUserDetails",
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "Get"
        }, new { @class = "button", id = "EditUserButton" }) 

如果这是可能的吗?任何想法

Any idea if this is possible?

推荐答案

在生成服务器上的操作链接,你可以把一些特殊的占位符用户名路径值:

When generating the action link on the server you could put some special placeholder for the UserID route value:

@Ajax.ActionLink(
    "Edit", 
    "EditUser", 
    "User",    
    new { 
        UserID = "__userid__" 
    },
    new AjaxOptions {
        OnSuccess = "ShowEditUserForm",
        UpdateTargetId = "EditUserDetails",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "Get"
    }, 
    new { 
        @class = "button", 
        id = "EditUserButton" 
    }
) 

,然后当你分配一个值隐藏字段在JavaScript中,你可以更新操作链接HREF还有:

and then when you assign a value to the hidden field in javascript you could update the action link href as well:

$('#EditUserButton').attr('href', function() {
    return this.href.replace('__userid__', $('#NewUserID').val());
});

这篇关于使用JavaScript ASP.Net MVC 3.0 Ajax.ActionLink动态对象路径的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:14