I am working on a MVC 3 app that requires at some point some data from the users. The data is then sent to an external DLL (I am not allowed to change it). The transfer is done by passing an object to a function so that object can be my Model for the View.
The problem is that I do not have access to add Attributes to the Model and I do not what to add a metadata class.
I decided to use a custom validation mechanism using JQuery so I made helper functions like this:
@helper TextBox(string name, object value = null)
{
var val = value ?? "";
<tr>
<td class="label">@name :
</td>
<td>
<input type="text" name="@name" id="@name" value="@val" />
</td>
</tr>
}
@helper ValidationMessage(string name)
{<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="@name"></span>}
@helper TextBoxRequired(string text, string fildName, object value = null, string message = "*")
{
var val = value ?? "";
<tr>
<td class="label">@text :</td>
<td>
<input type="text" name="@fildName" id="@fildName" value="@val" data-val="true" data-val-required="@message" />
@ValidationMessage(fildName)</td>
</tr>
}
I've included jquery-1.8.2, jquery.validate and jquery.validate.unobtrusive but it is not working.
Any help is appreciated.
Edit: web config settings:
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
And I am using Firefox,Chrome and IE for testing with JavaScript enable.
ClientValidationEnabledandUnobtrusiveJavaScriptEnabledunder AppSettings to true), or via code using the same keynames as static properties onHtmlHelper?