This is a migrated thread and some comments may be shown as answers.

[Solved] Problem w/ Editor Client Validation

0 Answers 24 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Péricles
Top achievements
Rank 1
Péricles asked on 05 Jul 2011, 08:33 PM
I have followed the steps to use the client validation, but the validation with DataAnnotations doesn't work!

I'm using Razor w/ view engine, and to test, I have created a dummy app too, the result is the same....fail =/


The validation fails when I submit the form


follow parts of Code:
My VIEW:
@model TelerikMvcApplicationPoc.Models.ModelMinha
 
@{
    ViewBag.Title = "Index";
}
@{ Html.EnableClientValidation(); }
 
<h2>Index</h2>
 
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>ModelMinha</legend>
 
        <div class="editor-label">
            @Html.LabelFor(e => e.Stringona)
        </div>
        <div class="editor-field">
        @(Html.Telerik().EditorFor(e => e.Stringona).Name("Stringona").Encode(false).Tools(tools => tools
                                .Clear()
                                .Bold().Italic().Underline()
                                .Separator()
                                .CreateLink().Unlink()
                            ))
            
            @Html.ValidationMessageFor(e => e.Stringona)
        </div>
 
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}
@{ Html.Telerik().ScriptRegistrar()
                 .DefaultGroup(group => group
                     .Add("MicrosoftAjax.js")
                     .Add("MicrosoftMvcValidation.js")); }
<div>
    @Html.ActionLink("Back to List", "Index")
</div>

My Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
 
namespace TelerikMvcApplicationPoc.Models
{
    [KnownType(typeof(ModelMinha))]
    public class ModelMinha
    {
        [AllowHtml]
        [Required(ErrorMessage = "Digite algo")]
        [StringLength(10, ErrorMessage = "Maior do que deve")]
        public string Stringona { get; set; }
    }
}

My Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TelerikMvcApplicationPoc.Models;
 
namespace TelerikMvcApplicationPoc.Controllers
{
    public class ModelController : Controller
    {
        //
        // GET: /Model/
 
        public ActionResult Index()
        {
            return View(new ModelMinha());
        }
 
    }
}
Tags
Editor
Asked by
Péricles
Top achievements
Rank 1
Share this question
or