如何在同一个控制器上使用多个操作?
我正在使用在 asp.net mvc 中打开新项目时出现的默认项目。
我在主控制器上添加了一个索引操作以接受来自文本框的值......就像这样
string strTest;
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection frm)
{
strTest = frm["testbox"];
return RedirectToAction("Index");
}
现在,我需要将输入的值显示给用户。我该怎么做呢?
我试过这个..
public ActionResult Index()
{
this.ViewData.Add("ReturnMessage", strValue);
return View();
}
以下是我的观点。。
<% using (Html.BeginForm())
{ %>
<p>
<%=Html.TextBox("testbox")%>
</p>
<p>
<input type="submit" value="Index" /></p>
<p>
<%= Html.ViewData["ReturnMessage"] %>
</p>
<% } %>
编译器通常不允许我添加具有相同构造函数的另一个索引来将输入的消息显示回用户,这在我知道的 c# 中是显而易见的。但是,那么我如何将消息返回给用户。谢谢