asp.net mvc model didn't receive on form submit -
I have written an asp.net mvc site that works fine on the local. But after publishing it, I have some problems with the model sent from the form. I think that it determines that my model state is not always valid. I could not find any data!
[HTPGet] Public Action Result Login () {Return View (); } [Http post] Public Action Result Log In (model.loginview model data) {if (! ModelState. ISI Walid) {return login (); } Teppelinties DB = new Templight (); UserAccount probableUser = db.UserAccounts.FirstOrDefault (p = & gt; p.UserName == Data Username & amp; p.Pass == Data.pass); If (the potential user == blank) {ModelState.AddModelError (string.Empty, "the name of the weak Abbas Afbarby وارد شده است!"); Return login (); } Session ["login"] = true; Session ["user name"] = potential user Username; Session ["course"] = potential user Course New Name; Session ["teacher name"] = potential user. Teacher name; Session ["real name"] = potential user Ryanelam; Redirect Action ("Index", "Home"); }
and the view is like this:
@ ModelTortoral.models.loginviewModel @ {ViewBag.Title = "ورود به سایت"; } & Lt; H2 & gt; ورود & lt; / H2 & gt; @using (Html.BeginForm ()) {@ * @ Html.AntiForgeryToken () * @ & lt; Div class = "form-horizontal" & gt; & Lt; H4 & gt; اطلاعات ورود را وارد کنید & lt; / H4 & gt; & Lt; Hour / & gt; @html Validity valid (true) & lt; Div class = "form-group" & gt; @ Html.LabelFor (model = & gt; model.UserName, new {@class = "control-label col-md-2"}) & lt; Div class = "col-md-10" & gt; @ Html.EditorFor (model = & gt; model.UserName) @ html.ValidationMessageFor (model => model.UserName) & lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; @ Html.LabelFor (model = & gt; model.Pass, new {@class = "control-label col-md-2"}) & lt; Div class = "col-md-10" & gt; @ Html.EditorFor (model = & gt; model.Pass) @ html.ValidationMessageFor (model => model.Pass) & lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt; Div class = "col-md-offset-2 col-md-10" & gt; & Lt; Input type = "submit" value = "ورود" class = "btn btn-default" /> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; } & Lt; Div & gt; @ Htmlconnellink ("bergatti bhanh", "index", "home") & lt; / Div & gt; @ Section scripts {@ Scripts.Render ("~ / bundles / jqueryval")}
and model class:
using the system; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.ComponentModel.DataAnnotations; Namespace temporal.models {public class login viewmodel {{Required (error message = "Name Caller's Big Wide!")] [Display (name = "Name Christian")] Public String Username {Received; Set; } [Required (error message = "Rosazaz عبور باید وارد شود!"]] [Display (name = "Rosas")] Public string pass {get; set;}}}
In See results:
Input:
Output Local:
Online Output at the host:
Try adding this filter
[ValidateAntiForgeryToken]
<
Edit
Validation set to instantly and validate your model in your received method.
[HTTPGet] Public Action Result Login () {var model = New loginwillmodel (); Return view (model);}
Comments
Post a Comment