我想調用一個控制器,當點擊視圖中的按鈕。如何在MVC中做到這一點?如何在點擊按鈕時調用控制器?
這是我的第一個控制器。
public ActionResult DetailForm()
{
graduandModel model = new graduandModel();
var ceremonyList = _ceremonyService.GetAllCeremonyByDate(DateTime.Now);
if (ceremonyList.Count == 0)
{
return Content("No ceremony can be loaded");
}
else
{
foreach (var c in ceremonyList)
{
model.AvailableCeremony.Add(new SelectListItem() {
Text = "Ceremony at " + c.ceremony_date.ToString(),
Value = c.ceremony_id.ToString() });
}
return View(model);
}
}
這是我的看法。
@{
Layout = "~/Views/Shared/_ColumnsThree.cshtml";
}
@model graduandModel
@using Nop.Web.Models.Hire;
@using Nop.Web.Framework;
@using Telerik.Web.Mvc.UI;
@using System.Linq;
<table>
<tr>
<td>
@Html.LabelFor(model => model.ceremony_id)
</td>
<td>
@Html.DropDownListFor(model => model.ceremony_id, Model.AvailableCeremony)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.first_name):
</td>
<td>
@Html.EditorFor(model => model.first_name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.middle_name):
</td>
<td>
@Html.EditorFor(model => model.middle_name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.last_name):
</td>
<td >
@Html.EditorFor(model => model.last_name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.student_id):
</td>
<td>
@Html.EditorFor(model => model.student_id)
</td>
</tr>
<tr>
<td colspan="2" class="buttons">
<input type="submit" id="btnsearchgraduand" name="btnsearch"
class="searchbutton" value="@T("Search")" />
</td>
</tr>
</table>
然後當我點擊搜索按鈕時,我想檢查輸入數據。 我應該寫新的控制器這樣
public ActionResult CheckDegreeDetails()
{
graduandModel model = new graduandModel();
var degreeList = _graduandService.GetGraduandByStudent(
model.ceremony_id, model.first_name,
model.middle_name, model.last_name);
return View(model);
}
或者......
我不知道怎麼稱呼控制器單擊按鈕時...