I'm trying to pass these textbox values to the controller:
@model DTOs.QuestionDTO
@{
ViewBag.Title = "AddQuestion";
}
<h2>AddQuestion</h2>
@using (Html.BeginForm("AddQuestionDB", "Exam"))
{
<fieldset>
<legend>Add Question</legend>
<div class="editor-label">
@Html.LabelFor(model => model.QuestionDes)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.QuestionDes , new { @id="question" , @name="question"})
@Html.ValidationMessageFor(model => model.QuestionDes)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Answer1)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Answer1 , new { @id="a1" , @name="a1"})
@Html.ValidationMessageFor(model => model.Answer1)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Answer2)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Answer2 , new { @id="a2" , @name="a2"})
@Html.ValidationMessageFor(model => model.Answer2)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Answer3)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Answer3 , new { @id="a3" , @name="a3"})
@Html.ValidationMessageFor(model => model.Answer3)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Answer4)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Answer4 , new { @id="a4" , @name="a4"})
@Html.ValidationMessageFor(model => model.Answer4)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Correct)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Correct , new { @id="correct" , @name="correct"})
@Html.ValidationMessageFor(model => model.Correct)
</div>
<p>
<input type="submit" value="Add" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to Login", "Login")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
this is how my controller method looks like:
public ActionResult AddQuestionDB(string question, string a1, string a2, string a3, string a4, string correct)
{
ViewBag.a1 = a1;
ViewBag.a2 = a2;
ViewBag.a3 = a3;
ViewBag.a4 = a4;
ViewBag.correct = correct;
return View();
}
And i have created a View to display this Viewbag variables... but these variables wont come up. it seem to be that these variables are null..
@{
ViewBag.Title = "AddQuestionDB";
}
<h2>AddQuestionDB</h2>
<p>@Session["q"]</p>
<p>@ViewBag.question</p>
<p>@ViewBag.a1</p>
<p>@ViewBag.a2</p>
<p>@ViewBag.a3</p>
<p>@ViewBag.a4</p>
<p>@ViewBag.correct</p>
this is how my DTO looks like:
namespace DTOs
{
public class QuestionDTO
{
public int ID { get; set; }
public string QuestionDes { get; set; }
public string Answer1 { get; set; }
public string Answer2 { get; set; }
public string Answer3 { get; set; }
public string Answer4 { get; set; }
public int Correct { get; set; }
}
}
Can you please explain, how i should do this?? thank you!!!