ASP.NET MVC ModelState Error display

  1. #1

    ASP.NET MVC ModelState Error display

    Hello!

    Could you help me please with displaying ModelState error on my form?
    I've been struggling with this for two days still no luck.

    Model
    public class PostModel
        {
            [Required]
            public string Author { get; set; }
    
            [Required]
            [StringLength(20, ErrorMessage = "Message should be from 5 to 20 characters", MinimumLength = 5)]
            public string Message { get; set; }
        }
    Controller
    public class BlogController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult PostMessage(PostModel post)
            {
                if (ModelState.IsValid)
                {
                    bool saveSucceed = Repository.Save(post);
                    if(!saveSucceed) ModelState.AddModelError("", "New post save failed");
                }
                return this.FormPanel(ModelState);
            }
        }
    View
    @model SampleExt.Models.PostModel
    @(Html.X().ResourceManager())
    
    @(Html.X().Window()
          .Height(150)
          .Icon(Icon.Add)
          .Title("Add Post")
          .Draggable(true)
          .Width(350)
          .BodyPadding(5)
          .Layout(LayoutType.Fit)
          .Items(
              Html.X().FormPanel()
                  .ID("PostForm1")
                  .Layout(LayoutType.Form)
                  .Border(false)
                  .BodyStyle("background-color:transparent;")
                  .Listeners(ls =>
                      {
                          ls.ValidityChange.Handler = "#{Button1}.setDisabled(!valid);";
                      })
                  .FieldDefaults(def =>
                      {
                          def.MsgTarget = MessageTarget.Qtip;
                      })
                  .Items(
                      Html.X().TextFieldFor(m=>m.Author).LabelAlign(LabelAlign.Top),
                      Html.X().TextAreaFor(m=>m.Message).LabelAlign(LabelAlign.Top)
                  )
                  .Buttons(
                      Html.X().Button()
                          .ID("Button1")
                          .Text("Post it")
                          .Disabled(true)
                          .Icon(Icon.Accept)
                          .DirectEvents(de => {
                                                  de.Click.Url = Url.Action("PostMessage");
                                                  de.Click.FormID = "PostForm1";
                          })
                  )
          )
    )
    For now I've got this error displayed like this
    Click image for larger version. 

Name:	error1.JPG 
Views:	153 
Size:	21.5 KB 
ID:	6436

    How can I get something like this?
    Click image for larger version. 

Name:	error_should.JPG 
Views:	145 
Size:	19.5 KB 
ID:	6437

    Thanks.
  2. #2
    Hi,

    Did you see this sample: http://mvc.ext.net/#/Models/Model_State/ ?

    On the page there is an DataView that uses an ModelStore as datasource.
    In the submit action this store is DataBinded and the ModelState is returned to the client.

    In the sample the error messages will be displayed in the DataView when validation fails.

    Hope this helps.

    Cheers
  3. #3

    ASP.NET MVC ModelState Error display

    Hello RandomEugene, lograstes fix the error. if achieved as if you could please share and I'm in the same problem.

Similar Threads

  1. Display error of Toolbar Overflow
    By howardyin in forum 2.x Help
    Replies: 8
    Last Post: Jan 11, 2013, 1:04 AM
  2. [CLOSED] Display error PartialView
    By bbo1971 in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 27, 2012, 12:26 PM
  3. [CLOSED] ModelState
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Feb 09, 2011, 4:47 PM
  4. [CLOSED] Fileuploadfield display error
    By reinout.mechant@imprss.be in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 18, 2009, 6:58 AM
  5. Please tell why display error like this
    By bruce in forum 1.x Help
    Replies: 0
    Last Post: Apr 27, 2009, 3:08 AM

Tags for this Thread

Posting Permissions