c# - Working with attribute routing in mvc -


on login page have dropdownlist change culture of application doing ajax call set culture. default have set 'en_us'.

my issue when login directly without changing culture able login successfully, when change culture , tries login, not able that. happening because of ajax call made, makes custom attribute not registered ?

also, login method has custom attribute defined. below code.

ajax call

 $('#ddllanguages').change(function () {         var val = $('#ddllanguages').val()         createcookie('culturecookie', val, 7);           $.ajax({             type: "post",             url: '/account/getculturenew',             data: { culturename: val },             success: function (result) {                  $("#logo-group").html('');                 $(document.body).html('');                 $(document.body).html(result);              },             error: function (data) {                 //alert('error');             }         });      }); 

ajax method in controller

 [httppost]     public actionresult getculturenew(string culturename)     {         if (!string.isnullorempty(culturename) & culturename.contains("#"))         {             string[] strdata = culturename.split('#');              if (strdata.length > 0)             {                 apptenant tenant = httpcontext.session.getobjectfromjson<apptenant>("tenantinfo");                  if (tenant != null)                 {                     tenant.loggedinculture = strdata[0];                     tenant.languageid = convert.toint32(strdata[1]);                      httpcontext.session.setobjectasjson("tenantinfo", tenant);                 }             }         }         list<selectlistitem> items = new list<selectlistitem>();         items = httpcontext.session.getobjectfromjson<list<selectlistitem>>("languagedata");          foreach (var item in items)         {             if (item.value == culturename)             {                 item.selected = true;             }             else             {                 item.selected = false;             }         }          var itemsstring = jsonconvert.serializeobject(items);          cookieoptions obj = new cookieoptions();         obj.expires = datetime.now.addmonths(3);         response.cookies.append("languagelist", itemsstring, obj);          var viewmodel = new lms_user { returnurl = string.empty, languagelist = items };          return view("login", viewmodel);     } 

login method

[httppost]     [allowanonymous]     [responsecache(nostore = true, location = responsecachelocation.none)]     [route("admin/login/{clietname}")]     public async task<iactionresult> login([bind(include: "email,password,rememberme")] lms_user model, string returnurl)     {           // login logic     } 

edit :- 1 login partial view

<div class="col-xs-12 col-sm-12 col-md-5 col-lg-4"> <div class="well no-padding">     <form action="@url.action("login", "account")" method="post" id="login-form" class="smart-form client-form">         <header>             @obj["singnin"]         </header>         @html.antiforgerytoken()          <fieldset>             <section>                 <label asp-for="languagelist">@obj["languagelist"] </label>                 @html.dropdownlist("languages", model.languagelist, null, new { id = "ddllanguages", @class = "form-control" })             </section>             <section>                 <label asp-for="email">@obj["email"]</label>                 <label class="input">                     <i class="icon-append fa fa-user"></i>                      @html.textboxfor(m => m.email, new { @class = "form-control" })                      <b class="tooltip tooltip-top-right"><i class="fa fa-user txt-color-teal"></i>>@obj["tooltipemail"]</b>                     <span asp-validation-for="email" class="text-danger"></span>                 </label>             </section>              <section>                 <label asp-for="password">@obj["password"]</label>                 <label class="input">                     <i class="icon-append fa fa-lock"></i>                     @html.passwordfor(m => m.password, new { @class = "form-control" })                     <b class="tooltip tooltip-top-right"><i class="fa fa-lock txt-color-teal"></i>@obj["tooltippassword"] </b>                     <span asp-validation-for="password" class="text-danger"></span>                 </label>                 <div class="note">                     <a href="@url.action("forgotpassword", "account")"><i class="fa fa-frown-o"></i> @obj["forgot_password?"]</a>                 </div>             </section>              <section>                 <label class="checkbox">                     <input asp-for="rememberme" />                      <i></i>@obj["remember_me"]                 </label>             </section>              <footer>                 <button type="submit" class="btn btn-primary">                     @obj["singnin"]                 </button>             </footer>           </fieldset>     </form>   </div> @{ await html.renderpartialasync("_socialmedia"); } 

edit 2:-entire login view

<div id="content" class="container">     <div class="row">          @{ await html.renderpartialasync("_logintext"); }         @{ await html.renderpartialasync("_loginpartial"); }      </div> </div> 

however if add location.reload() in ajax success function, changing culture can login successfully.

any on appreciated !

when $(document.body).html(result);

the action part of form goes missing. hence not know post to.

hope have been of :)


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -