I'm just looking for a better way to do the following :
I've got an html select :
<form method="post" action="/Account/ChangeUserRole">
<select name="Val" onchange="this.form.submit();" class="span2">
@foreach (var r in ViewBag.UserRoles)
{
@if (u.UserRole.ID == r.ID)
{
<option selected="selected" value="@u.ID/@r.ID">@r.Name</option>
}
else
{
<option value="@u.ID/@r.ID">@r.Name</option> // <-- better way?
}
}
</select>
</form>
I'm posting it as "userid/roleid" and on the controller side doing a string.Split on / to split u.ID and r.ID
I would like to know if it's possible to post it so my controller get's them in this way :
[HttpPost]
public IActionResult ChangeUserRole(int UserID, int RoleID)
Instead of this witchcraft:
[HttpPost]
public IActionResult ChangeUserRole(string Val)
{
char[] splitChar = new char[] { '/' };
string[] s = Val.Split(splitChar);
int UserID = Convert.ToInt32(s[0]);
int RoleID = Convert.ToInt32(s[1]);
}
Sorry for the long post. Hope my question makes sense. I'm not such a big fan of html helpers.
Side note: I'm using MVC 6, ASP 5 - RC1
Appreciate the help
Cheers!