asp.net mvc - Client Side Validation fails when moving to viewmodel -
asp.net mvc - Client Side Validation fails when moving to viewmodel -
this seems mutual question lots of reasons not seem apply situation. have create page using asp.net mvc 2 , using typed view class generated dataenities framework.
<%@ page title="" language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<mvc_edi.models.wyscustomerendpoint>"" %>
i made validation class bound the info class.
[metadatatype(typeof(endpointvalidation))] public partial class wyscustomerendpoint { } [bind()] public class endpointvalidation { [required(errormessage = "please come in end point name")] public string custname { get; set; }
and able utilize client side validation on create page. had requirement add together dropdown list box on create page, switched view utilize viewmodel instead of info class using.
public class createeditcustomerendpointsviewmodel { public wyscustomerendpoint customerendpoint {get; set;} public list<selectlistitem> defaultlocationlist { get; set; } }
and here view header using new viewmodel.
<%@ page title="" language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<mvc_edi.viewmodles.createeditcustomerendpointsviewmodel>" %>
but when view gets loaded getting error formelement null when tries set value ? error out here inteh microsofymvcvalidation.js file , formelement array null.
formelement['__mvc_formvalidation'] =
i suspect need add together sort of info annotation or attribute either view model or that. not sure where? , surprisingly seems work out fine in firefox 5 bombs in ie9?
edit: reply. yes believe instantiating object before adding viewmodel , using html.helper objects? here code.
wyscustomerendpoint ep = new wyscustomerendpoint(); ep.buyerid = id; var viewmodel = new createeditcustomerendpointsviewmodel() { customerendpoint = ep }; homecoming view(viewmodel);
and in view
<div class="editor-label"> <%: html.label("name") %> </div> <div class="editor-field"> <%: html.textboxfor(model => model.customerendpoint.custname) %> <%: html.validationmessagefor(model => model.customerendpoint.custname) %> </div>
cheers
bob
you're maybe doing this, without seeing relevant bits of code don't want assume. so, create sure instantiating wyscustomerendpoint object , sending view controller method. using html helpers input elements validating on. eg.
html.textboxfor(model => model.wyscustomerendpoint.custname)
asp.net-mvc
Comments
Post a Comment