Hi Rahul Yadav,
Seems your question needs more details.
1. Are you loading data from any DB?
2. How you are giving a control to the user to select the answer?
If it is a Radio Button list While on click of Post button you can add a click event in JavaScript and you can read the selected option. From JavaScript function you can call controller and pass the data.
In that method you can get the answer by passing QuestionNo to DB.
Here my Example with a Check Box list (as i also don't have much idea about MVC):
$("#PostAnswer").click(function () {
var questionlist = [], counter = 0;
$('.chkbox1').each(function () {
if ($(this).is(':checked')) {
var questionID = evalVM[0].ID;
var id = $(this).attr('ID');
var question= {
QuestionID: questionID,
answerID : id
};
questionlist .push(question);
}
});</pre>
Then you can call the controller by passing the list
var url = baseurl + 'EvaluationController/ValidateAnswers
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: JSON.stringify(questionlist ),
contentType: 'application/json; charset=utf-8',
success: function (result) {
if (result > 0) {
alert('');
}
}
});
[HttpPost]
public JsonResult ValidateAnswers(List<evalmodel> evalVM= null)
From controller you can validate against DB.
Sorry If anything is wrong. Even am also new to MVC, But i explained how we are using in our current project.</evalmodel>