asp--forms
1、html helper
<%: Html.TextBoxFor(model => model.Title,...
2、所见所得
http://stackoverflow.com/questions/1559800/get-custom-attributes-from-lambda-property-expression#1560950.
3、增加属性
<%: Html.TextBoxFor(model => model.Title, new {disabled="true", alt="alt text here"}) %>-----不可用。有ALT
4、按回车时候,默认提交按钮
<input type="submit" name="btnSubmit" id="submitButton" value="Submit" />
<input type="submit" name="btnSubmit" id="cancelButton" value="Cancel" />
<input type="submit" name="btnSubmit" id="cancelButton" value="Cancel" />
<% using (Html.BeginForm("Article", "Home", FormMethod.Post,new Dictionary<string, object> { { "data-default",
"submitButton" }, { "id", "form1" } })) { %>
"submitButton" }, { "id", "form1" } })) { %>
<script type="text/javascript">
var buttonKeys = { enterKey: 13 };
$(function () {
$("#form1").keypress(function (evt) {
if (evt.which == buttonKeys.enterKey) {
evt.preventDefault();
var defaultButtonId = $(this).attr("data-default")
if (defaultButtonId != null)
$("#" + defaultButtonId).click();
}
});
});
</script>
$(function () {
$("#form1").keypress(function (evt) {
if (evt.which == buttonKeys.enterKey) {
evt.preventDefault();
var defaultButtonId = $(this).attr("data-default")
if (defaultButtonId != null)
$("#" + defaultButtonId).click();
}
});
});
</script>
5、实现自动回传
<% using (Html.BeginForm()) {%>
<%= Html.DropDownList("id",
new SelectList(ViewData["ArticleList"] as List<Forms.Models.Article>, "ID", "Title"),
new { onchange ="this.form.submit();"}) %><input type="submit" value="Change"/>
<% } %>
new SelectList(ViewData["ArticleList"] as List<Forms.Models.Article>, "ID", "Title"),
new { onchange ="this.form.submit();"}) %><input type="submit" value="Change"/>
<% } %>