单击视图中的按钮时,我想调用控制器。如何在 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);
}
或者...
单击按钮时我不知道如何调用控制器...