提交后显示输入中的文本

时间:2011-11-02 11:54:56

标签: asp.net asp.net-mvc-3 razor

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。按钮的标准类型是提交。

1 个答案:

答案 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 />标记,因此在提交时应该发布。

相关问题