请参阅下面的 index.cshtml 代码:-
列表显示如下&字符串是标题,我将公司 ID 发送给控制器
@model MvcApplication3.Models.Company
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.CompanyName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Template)
</td>
<td>
@Html.DisplayFor(modelItem => item.Caption)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.CompanyID }) |
@Html.ActionLink("Details", "Details", new { id = item.CompanyID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.CompanyID })
</td>
</tr>
}
</table>
</div>
@using (Html.BeginForm("GetCaption", "Company", FormMethod.Get))
{
@Html.TextBox("txtCmpID")
<input id="btnGetCaption" type="submit" value="Get Caption" />
}
<span style="color: Black; position: absolute; top: 100px; left: 20px;">
@text =
</span>
Controller.cs 文件中的代码:-
private DynaPortalContext db = new DynaPortalContext();
//
// GET: /Company/
public ViewResult Index()
{
return View(db.Companies.ToList());
}
//
// GET: /Company/caption
[ActionName("GetCaption"),HttpPost]
public ActionResult GetCaption(string txtCmpID)
{
Company company = db.Companies.Find(txtCmpID);
return View("Index",company);
}
请告诉我如何将控制器的 GetCaption() 方法生成的标题显示到 @text=... 中的视图中