I have a requirement to pass value from view to controller in the Html.BeginForm()
@using (Html.BeginForm("ChangeRole", "Login", null, FormMethod.Post, null, new { id = "SubmitRole" }))
{
@Html.AntiForgeryToken()
@foreach (var item in (@HttpContextAccessor.HttpContext.Session.GetObjectFromJson<UserRoleLevelDetails>("GetAllUsersList")))
{
//..
if (@vr != @HttpContextAccessor.HttpContext.Session.GetString("Role").ToString())
{
<a class="@vr" [email protected]("{0}", @item.Role_Level_Name) onclick="Change_Role(this)">@vr</a><br />
}
//..
}
}
function Change_Role(e) {
var ChangedRole = $(e).attr('class');
$('#UserMainRole').val(ChangedRole);
$("#SubmitRole").submit();
e.preventDefault();
};
So, while submitting I need to pass value of ChangedRole
to the controller.
$('#UserMainRole')
meant to reference? Is it a form element which can contain a value? Is it contained within the form? When you debug in your browser, is that element's value updated? What specifically fails? – David