- 我想發送消息到用戶ID = 3,I輸入在一些文本文本區域並單擊保存以發佈表單
- Message()[post]操作保存更改,將SomeText的值重置爲空字符串並返回到視圖。
在這一點上我希望因爲我已經把計算機[「SomeText」則會]到的String.Empty重置textarea的值
爲什麼文本區域價值不更新爲空字符串後動作之後文本區是空的?
這裏是動作:
[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>
我不認爲有任何錯誤。我以另一種形式出現了同樣的問題。我一直在撓撓我的頭幾天,但我無法找到爲什麼會發生這種情況。當您無法控制發佈後的表單中顯示的內容時,這非常煩人。我想知道我是否在做任何不尋常的事情或錯誤的事情。 – xraminx 2009-04-25 00:25:54