开发者

Passing data to controller while Using URL.Action in jQuery template in Asp.Net MVC dynamic views

开发者 https://www.devze.com 2023-02-26 07:01 出处:网络
I have a dynamic view created using jQuery template. The UI is basically a grid with last column being a hyper-linked image. On click on that image i want to pass some data to the controller and that

I have a dynamic view created using jQuery template. The UI is basically a grid with last column being a hyper-linked image. On click on that image i want to pass some data to the controller and that data is present in some other column of the same row. Following is the markup of the code

UI :

{{each Results}}
        <tr>
            <td>${UserName}</td>
            {{if IsActive === 'True'}}
                <td><a href=<%: Url.Action("Test","User",new {userName=???,mode="DeActivate"}) %>><img></img><a></td>
            {{/if}}                
        </tr>
    {{/each}}    

Controller :

public A开发者_如何学编程ctionResult Test(string userName,string mode)
    {
    }

Basically I want to associate the ${UserName} value to userName field in Url.Action's parameter list.

Most of the examples I have seen on Url.Action or Html's helper action methods have string data as parameters. I want to know whether it is possible to read data from other controls in the page inside Url.Action parameter list.


Try like this:

<a href=<%: Url.Action("Test", "User", new { mode = "DeActivate" }) %>&amp;userName=${$item.urlEncodeUserName()}>
    ...
</a>

where you have defined:

$('#someTemplate').tmpl(contacts, {
    urlEncodeUserName: function () {
        return encodeURIComponent(this.data.UserName);
    }
}).appendTo('#someContainer');
0

精彩评论

暂无评论...
验证码 换一张
取 消