these are my models.
public class Question
{
private string _questionNo;
private string _questionText;
private List<Option> _options;
public List<Option> Options
{
get { return _options; }
set { _options = value; }
}
public string QuestionNo
{
get { return _questionNo; }
set { _questionNo = value; }
}
public string QuestionText
{
get { return _questionText; }
set { _questionText = value; }
}
}
public class Option
{
private string _optionText;
private string _optionNumber;
public string OptionText
{
get { return _optionText; }
set { _optionText = value; }
}
public string OptionNumber
{
get { return _optionNumber; }
set { _optionNumber = value; }
}
}
these is my controller
public ActionResult GetQuestion(int id,string gid)
{
var vewmodel = ques.GetQuestion(Gid, Uid, id);
return View(vewmodel);
}
this is my view.
@model mobilesurveys.mt.Models.Question
@{ ViewBag.Title = "Question"; }
<div data-role="header" data-theme="b">
<h1>
@Model.SurveyName</h1>
</div>
@if (@Model.QuestionType == 7)
{
<div data-role="fieldcontain">
@using (Html.BeginForm("SaveDropDown", "GetQuestion", Model))
{
@Html.AntiForgeryToken()
<fieldset>
<label class="select">@Model.QuestionText
</label>
<br />
<select name="selectedObjects" id="selectchoice1" data-native-menu="false">
<option value="--select--">--Select--</option>
@foreach (var item in Model.Options)
{
if (@item.IsAnswer == true)
{
<option selected="selected" value="@item.OptionNumber">@item.OptionText</option>
}
else
{
<option value="@item.OptionNumber">@item.OptionText</option>
}
}
</select>
</fieldset>
<p>
<input type="submit" value="Next" />
</p>
}
</div>
}
so i am binding the optoins based on QuestionTypeId(RadioButtions,CheckBoxes,TextBox,Select). Now I want to validate the data at clientside. I am using Jquery Scripts.
How can i write the validations. any help is appreciated.
Thanks.
There are two methods.
1.You can do this by adding annotation in the model class
add like this line in model
in this way add annotation above the variable where you want.
Or
2.You can use jquery code to validate.
I am giving you the code
In this way you can check field in jquery .
Reply me if you find any prob