感到困惑的ASP.NET MVC和服务器控件 [英] Confused about ASP.NET MVC and Server Control
问题描述
我看一个人不能使用ASP.NET MVC与服务器控件具有ViewState中包括文本框?
I read that one cannot use ASP.NET MVC with Server Control which have ViewState including TextBox ?
http://forums.asp.net/t/1216834.aspx
服务器控件不需要
ViewState的全面功能将运行
在MVC,但任何需要
回发到正常工作不会的。
Server controls that do not require ViewState to fully function will work in MVC, but anything that requires PostBack to work properly will not.
所以可绑定,只读控制样
直放站的工作,但输入
像DropDownList控件和
文本框不会的。
So bindable, read-only controls like the Repeater will work, but input controls like the DropDownList and TextBox will not.
我应该用什么话,如果我甚至不能用文本框?
What should I use then if I cannot even use TextBox ?
推荐答案
ASP.NET和ASP.NET MVC都使用后端编码约定来渲染HTML标记。 ASP.NET中的约定是使用控制类,并在ASP.NET MVC的约定是使用的HtmlHelper
扩展方法。
ASP.NET and ASP.NET MVC both use a backend coding convention to render HTML markup. In ASP.NET the convention is to use Control classes, and in ASP.NET MVC the convention is to use HtmlHelper
extension methods.
借助的TextBox ASP.NET控件用下面的ASP.NET标记
<asp:TextBox id="sample_tbx" Text="Sample Default Value" runat="server" />
呈现以下HTML标记
renders the following HTML markup
<input type="text" name="sample_tbx" id="sample_tbx" value="Sample Default Value" />
要获得在一个MVC视图中的的HtmlHelper
扩展方法相同的结果,该公约是使用的 文本框()
扩展方法。例如,
To get the same result with an HtmlHelper
extension method in an MVC View, the convention is to use the TextBox()
extension method. For example,
<%= Html.TextBox("sample_tbx", "Sample Default Value") %>
在ASP.NET或ASP.NET MVC,HTML标记可以通过内联写的。所以,简单地写
In either ASP.NET or ASP.NET MVC, html markup can be written inline. So, simply writing
<input type="text" name="sample_tbx" id="sample_tbx" value="Sample Default Value" />
是有效期为ASP.NET的WebForms或ASP.NET MVC。
is valid for either ASP.NET WebForms or ASP.NET MVC.
这篇关于感到困惑的ASP.NET MVC和服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!