Dear All;

Is there someone that has got idea?

Best Regards

2015-03-30 22:48 GMT+03:00 Atilla İlhan KARTAL <[email protected]>
:

> Dear All;
>
> I am newbie at MVC 5. I am using Nhibernate, FluentValidation and MVC 5.
> I have a problem with validation. I think maybe this group users know
> solution.
>
> I want to use Complex Object type. I binded Site Property a dropdown Page
> model. I loaded Page form and post data. My model Site property has ID
> (ValueMember) value and Domain (DisplayMember) value. This is no problem I
> am using Nhibernate Merge method for save. FluentValidation Validate Site
> property and ModelState.IsValid is false. Because My Site Validator has
> RuleFor(x=>x.Title).NotEmpty(). ModelState Errors has this rule error.
>
> How can i solve this problem or How can i use DropDown for Relational
> Model?
>
> Best Regards.
>
>
>
> *Models*
>
> [Validator(typeof(PageValidator))]
>     public class Page : Persist<Page>
>     {
>         [Key]
>         public virtual long ID { get; set; }
>         public virtual Site Site { get; set; }
>         public virtual Page Parent { get; set; }
>         public virtual string Title { get; set; }
>         public virtual string Slug { get; set; }
> ...
> ..
> ..
> }
>
>
> [Validator(typeof(SiteValidator))]
>     public class Site : Persist<Site> , IHasDefaultValue
>     {
>         [Key]
>         public virtual long ID { get; set; }
>         public virtual string Title { get; set; }
>         public virtual string Description { get; set; }
>         public virtual string Keywords { get; set; }
>         public virtual string Domain { get; set; }
> ...
> ...
> ...
> ..
> }
>
> *View*
>             <div class="form-group">
>                 @Html.LabelFor(x => x.Site, new {@class = "col-sm-3
> control-label"})
>                 <div class="col-sm-6">
>                     @Html.DropDownListFor(x => x.Site.ID,
>                     new SelectList(Site.List(), "ID", "Domain")
>                     , new { @class = "form-control" })
>                     @Html.ValidationMessageFor(x => x.Site, null, new
> {@class = "help-inline error"})
>                 </div>
>             </div>
>
> *Controller*
>
> [HttpPost]
>         [ValidateAntiForgeryToken]
>         public ActionResult Create(Page model, string command)
>         {
>             if (ModelState.IsValid) /// this always false because Site
> property has only ID and Domain property value. Validators Validate Site
> property
>             {
>                 try
>                 {
>                     BeforeCreate(model);
>                     model.Save();
>                     AfterCreate(model);
>                     if (command=="SaveAndStay")
>                     {
>                         return RedirectToAction("Update", new { id =
> model.GetId() });
>                     }
>                     else if (command == "SaveAndNew")
>                     {
>                         return RedirectToAction("Create");
>                     }
>                     else
>                     {
>                         return RedirectToAction("Index");
>                     }
>                 }
>                 catch (Exception ex)
>                 {
>                     ModelState.AddModelError("", ex.Message);
>                 }
>             }
>             return View("Create", model);
>         }
>
> --
> Atilla İlhan KARTAL
> Web Application & Software Architect
> (Java & PHP & Registered Android Developer)
> Kuşadası / Aydın / Turkey
> www.atillailhankartal.com.tr
> twitter.com/TrojanMyth
>



-- 
Atilla İlhan KARTAL
Web Application & Software Architect
(Java & PHP & Registered Android Developer)
Kuşadası / Aydın / Turkey
www.atillailhankartal.com.tr
twitter.com/TrojanMyth

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to