2011-11-02 80 views
-3

Hy!提交後顯示輸入文字

我想說明從輸入後開始提交

我的代碼頁的文本:

@{ 
    ViewBag.Title = "Login"; 
} 
@{ 
    if (ViewData["uname"]!=null) 
    { 
      <div> 
      Username: @ViewData["uname"] //The Text from the input should be displayed here after submit 
      @Session["uname"] = @ViewData["uname"] 
      </div> 
    } 
} 
<h2>Login</h2> 
<h4>Username:</h4> 
<input type="text" name="uname" value="" /> //Input 
<button /> 

當我按下按鈕沒有出現。來自輸入的文本應該顯示abouth。提交按鈕的標準類型。

+0

你能解釋你到底在做什麼嗎?你想在哪裏顯示文字? –

回答

0

試試這個:

@{ 
    ViewBag.Title = "Login"; 
} 
@{ 
    if (ViewData["uname"]!=null) 
    { 
      <div> 
      Username: @ViewData["uname"] 
      @Session["uname"] = @ViewData["uname"] 
      </div> 
    } 
} 
<h2>Login</h2> 

@using (Html.BeginForm()) 
{ 
    <h4>Username:</h4> 
    <input type="text" name="uname" value="" /> 
    <input type="submit" value="Submit" /> 
} 

它使用一個的HtmlHelper創建<form />標籤周圍,所以在提交應該張貼。

+0

對我不起作用 – test123123

+0

@ test123123在相應的控制器中是否有POST(具有屬性'[HttpPost]')動作來處理這篇文章? – 2011-11-02 12:01:59

+0

控制器:公共類UserController中:控制器 { // // GET:/用戶/ 公共的ActionResult指數() { 返回查看(); } public ActionResult Login() { return View(); } } – test123123