mvc3 DataAnnotations has a Description attribute:
e.g.
[Display (Name="Title", Description="description about the title")]
public string Title { set; get};
in my view, I want to use jquery on .blur show the Description text that was entered.
<script type="text/javascript">
$(function () {
$("#title").blur(function () {
???
});
});
@Html.LabelFor(model => model.Title)
//description here, not sure how to map it.
@Html.LabelFor()//description would go here
@Html.TextBoxFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
thx!
I dont think adding Description will add a title tag to your input element. You may probably want to mention that when you create the text box like this
that will generate a title tag for your input element and as minus4 mentioned, you can use jQuery to access that.
You probably want to use a generic selector instead of specific selector (ID), something like a class name of all those input elements
EDIT : based on the comment about generic selector and specific selector
ID should be unique for each element, So If you have 8 elements, there will (and should) be 8 unique ids for the elements. in that case, you need to bind your function to 8 different items by ID like this
But if you have a common class which is being applied to all these elements , you may use it like that (The below will bind the function to all elements which has the css class value
mySimpleClassYou may use the other selectors like Child selectors. (The below code will bind your functionality to all input element of type text which is present in the
divContainerdivTo Add the Css class to your input element while using Html.TextBox for HTML helper, you may use it like this