0
votes

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.

In what way does the code shown not work as expected? What element is $('#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
maybe something like this: stackoverflow.com/questions/45872496/…steb
Can you provide a minimal reproducible unit?Chen