Sorry, I though you were using WebApi - the third solution (right at the bottom) is solution using just MVC...
If not interested in WebApi solution, jump to the bottom...
The easy way to do this is to use [FromUri] in your api controller as follows:
Improved answer (2) below (but read the first solution now to understand the second)
[Route("api/Values/Add")]
[HttpGet]
public string Add([FromUri] int userId, [FromUri] int userRole)
{
return "Id: " + userId + ", RoleId:" + userRole;
}
In the view you use the following:
<a href="api/Values/Add/?userId=@Model.UserId&userRole=@Model.UserRole" title="Click here to edit">Click here to edit</a>
The above can be demonstrated at benemanuel.net/Testing
In this example the userId and userRole are simply returned as a string.
If you want to do more complex stuff, consider using json - if you want help with this, contact me.
Solution 2==================
Instead of above api controller code, use the following:
[Route("api/Values/Add2")]
[HttpGet]
public string Add2([FromUri] User user)
{
return "Id: " + user.UserId + ", Role: " + user.UserRole;
}
This assumes a class called User that has UserId and UserRole properties.
Third Solution - MVC only====================
Simply use:
The anchor link is:
<a href="Testing/Testing/?userId=@Model.UserId&userRole=@Model.UserRole" title="Click here to edit">Click here to edit</a><br /><br /><br />
public ActionResult Testing(User user)
{
return View(user);
}
Again this assumes class User with UserId and UserRole properties...
The following view uses the User as a model passed in (as demonstrated as benemanuel.net/Testing - third link down...):
<h2>Testing</h2>
Id: @Model.UserId<br/><br />
UserRole: @Model.UserRole
Sorry for messing with your head with WebApi stuff (though WebApi is pretty cool for this kind of thing).
Ben