How to Validate a strong type view in MVC3 without a model

I've got stuck with my project. The project has 3 layers:

  1. Data access with a data model.
  2. A WCF service that retrieve data from de data access data model and sends a serialized class.
  3. A MVC web application that connects to a wcf service.

The wcf service has classes with procedures that retrieve data from the other layer (data access layer) and returns to the mvc application (there's no problem with this) I've created a strong type view (from the wcf service reference) that shows product categories and it does very well buy I donĀ“t know how to validate this view!

I've seen many articles about validation and most of that are using model and data annotations but it's not my case. I found some articles about jquery validations but I've tried and nothing happens... here is the code of the view:

@model SkySolutionsMVC3.ProductCategoryServiceReference.CompositeProductCategory
    ViewBag.Title = "Edit";
<script src="@Url.Content("~/Scripts/jquery-1.7.2.js")" type="text/javascript"></script>
<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())
        <legend>Product Category</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Enabled)
        <div class="editor-field">
            @Html.EditorFor(model => model.Enabled)
            @Html.ValidationMessageFor(model => model.Enabled)
        @Html.HiddenFor(model => model.Id)
        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        <div class="editor-field">
            @Html.EditorFor(model => model.Name, new { id="Name"})
            @Html.ValidationMessageFor(model => model.Name)
            <input type="submit" name="btnSave" value="Save" />
    @Html.ActionLink("Back to List", "Index")

Please help! I need some ideas...Thanks.


I am not entirely sure wat it is you are after, but if you are saying that you essentially need to control a class you imported from elsewhere, then how about this: write your own class, inherit from the class you are using as a model now and inherit from IValidatableObject, then either add the appropriate annotations to overridden properties or implement the Validate method, something like this:

public class MyClass : SkySolutionsMVC3.ProductCategoryServiceReference.CompositeProductCategory, IValidatableObject
    public override string Name
        get { return base.Name; }
        set { base.Name = value; }

    public IEnumerable Validate(ValidationContext validationContext)
        if (Name.Length != 5)
            yield return new ValidationResult("Name must be exaclty 5 characters long", new string[]{"Name"});

Need Your Help

cocoa:I want to know the location of the status bar icon on the screen

objective-c xcode macos cocoa

I want to know the location of the status bar icon on the screen