up vote 0 down vote favorite
share [g+] share [fb]

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 ActionResult 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.

link|improve this question

feedback

1 Answer

up vote 1 down vote accepted

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');
link|improve this answer
I tried the above approach and I am getting "this.data.UserName" as undefined. If I hard-code some value then the functionality is working fine. Is "$item" the standard way of accessing the current record in template ? – Pawan Mishra Apr 17 '11 at 6:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.