asp.net mvc - Validation Message MVC -



asp.net mvc - Validation Message MVC -

my code followed , error message not displayed:

index.cshtml

@model webapp.models.orderitems @using (html.beginform("savetodb", "home", formmethod.post, new { @class = "form-group", role = "form" })) { @html.partial("information") }

partial : information.cshtml

@model webapp.models.orderitems <div class="col-lg-4"> <div class="form-group"> <label for="input1" class="col-lg-4 control-label">@html.labelfor(model => model.clinfo.clientname)</label> @html.editorfor(model => model.clinfo.clientname, new { style = "width:250px" }) @html.validationmessagefor(model => model.clinfo.clientname) </div> </div>

model :

public class orderitems { public infoclinfo{ get; set; } }

model : class infos

public class info { [display(name = "client name")] [required] public string clientname{ get; set; } }

the controller

[httppost] [multiplebutton(name = "action", argument = "savetodb")] public actionresult savetodb(orderitems client) { var errors = modelstate.values.selectmany(v => v.errors); if (modelstate.isvalid) { if (_db == null) _db = new orderdb(); orderitems clientorig = session["clientobj"] orderitems; clientorig.clinfo = client.clinfo; session["clientobj"] = null; } homecoming redirecttoaction("index", "home"); } [authorize] public actionresult index (orderitems client) { int clientid = convert.toint32(session["client"]); if clientid == 0) { clientid = 2; session["client"] = clientid; } if (session["clientobj"] == null) { client = new orderitems(); client.clorderid = 123; session["clientobj"] = client; } else { client = session["clientobj"] orderitems } homecoming view(client); }

on post modelstate.isvalid homecoming false true, don't have message tell user error fixed.

i tried add together : @html.validationsummary(true) after beginform , didn

any thought please

thanks

you cannot utilize redirecttoaction if want retain model state. errors , not kept in modelstate object, , when redirect action it's performing new action, starts fresh clean slate.

you need homecoming view in original action.

asp.net-mvc asp.net-mvc-4

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -