I use unit framework 4 and MVC 2.
I have an address unit, contact, company.
There is a connection between contact and address and company and address. A contact may have an address and the company may also have an address.
I made a partial view of
& lt; Div class = "editor" & gt; & Lt;%: Html.HiddenFor (Model = & gt; Model. Address ID)% & gt; & Lt;%: Html.HiddenFor (Model = & gt; Model. Address ID)% & gt; & Lt; Div class = "editor-label" & gt; & Lt;%: HTML.LabelFor (model = & gt; model.civicNumber)% & gt; & Lt; / Div & gt; & Lt; Div class = "editor-field" & gt; & Lt;%: Html.TextBoxFor (model = & gt; model.civicNumber)% & gt; & Lt;%: HTML Validation message (Model = & gt; Model. Civicumber)% & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "editor" & gt; & Lt; Div class = "editor-label" & gt; & Lt;%: HTML.LabelFor (model = & gt; model.Street)%> & Lt; / Div & gt; & Lt; Div class = "editor-field" & gt; & Lt;%: Html.TextBoxFor (model = & gt; model.Street)%> & Lt;%: HTML Validation message (model = & gt; model.Street)%> & Lt; / Div & gt; & Lt; / Div & gt; ......
I call this partial view in the company view with my contact and editor.
In the address class, I had some validity.
Example: Civic number is required. [Required (Error Message = "Civic Number Required")] [DisplayName ("Civic Number")] {Receive Public Commodity; Set; }
Is it possible to activate this contact, when I contact the call address in other words. If I call from the company.Cakes, then I do not need any verification for the address fields. If I call address .ascx from contact view, then I need verification for the address field.
Hope someone can understand.
I'm not completely sure but give it a shot.
% bool OutputValidation = this.ViewContext.Controller.ViewData.Model.GetType () == Type (contact)%> & Lt; Div class = "editor" & gt; & Lt;%: Html.HiddenFor (Model = & gt; Model. Address ID)% & gt; & Lt;%: Html.HiddenFor (Model = & gt; Model. Address ID)% & gt; & Lt; Div class = "editor-label" & gt; & Lt;%: HTML.LabelFor (model = & gt; model.civicNumber)% & gt; & Lt; / Div & gt; & Lt; Div class = "editor-field" & gt; & Lt;%: Html.TextBoxFor (model = & gt; model.civicNumber)% & gt; & Lt;%: Output Verification? Html.ValidationMessageFor (model => model.civicNumber): ""%> & Lt; / Div & gt; & Lt; / Div & gt;
What you're doing is getting a model of parental scene. Then just check it out.
Comments
Post a Comment