我想通过/ MyController / Message / 3向userID = 3发送一条消息
这执行Message()[get]操作,我在文本区域中输入一些文本,然后单击“保存”以发布表单
Message()[post]操作保存更改,将SomeText的值重置为空字符串,然后返回视图。
此时,我希望文本区域为空,因为我已将ViewData [“ SomeText”]设置为string.Empty
为什么后操作后文本区域值未更新为空字符串?
操作如下:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Message(int ID)
{
ViewData["ID"] = ID;
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Message(int ID, string SomeText)
{
// save Text to database
SaveToDB(ID, SomeText);
// set the value of SomeText to empty and return to view
ViewData["SomeText"] = string.Empty;
return View();
}
和对应的视图:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm())
{ %>
<%= Html.Hidden("ID", ViewData["ID"])%>
<label for="SomeText">SomeText:</label>
<%= Html.TextArea("SomeText", ViewData["SomeText"]) %>
<input type="submit" value="Save" />
<% } %>
</asp:Content>
心有法竹
慕尼黑8549860
相关分类