1. MVC HTMLHELPER 방법
1.
html.beginform (ActionName, Control기 이름, 메소드, htmlattributes) {}2.
beginrouteform 메소드 (htmlhelper, 문자열, 개체, formmethod)
2. 전통적인 양식 Aciton 속성 제출
3. jQuery+ajax 제출 양식
4. MVC 컨트롤러 컨트롤러 및 양식 매개 변수 전달
MVC HTMLHELPER 방법
1. html.beginform (ActionName, Control기 이름, 메소드, htmlattributes) {}
참고 : 버튼을 포함하여 제출할 모든 콘텐츠는 {} 내에 있어야합니다.
매개 변수
htmlhelper 유형 : System.Web.mvc.htmlHelper
이 메소드는 HTML 헬퍼 인스턴스를 확장합니다. ActionName 유형 : System.String
작동 방법의 이름. 컨트롤러 이름 유형 : System.String
컨트롤러의 이름. RoutEvalues 유형 : System.Object
라우팅 매개 변수를 포함하는 객체. 객체의 특성을 확인함으로써 매개 변수는 반사를 사용하여 검색됩니다. 이 객체는 일반적으로 Object Initializer 구문을 사용하여 생성됩니다. 방법 유형 : System.Web.MVC. Formmethod
양식을 처리하는 데 사용되는 HTTP 방법 (GET 또는 POST). htmlattributes 유형 : System.Object
요소를 설정할 HTML 속성을 포함하는 객체.
반환 값
유형 : System.Web.mvc.html.mvcform
<form> 태그 시작.
사용 지침
Visual Basic 및 C#에서는이 메소드를 유형 htmlhelper의 모든 객체에 대한 인스턴스 메소드로 호출 할 수 있습니다. 인스턴스 메소드 구문을 사용 하여이 메소드를 호출하면 첫 번째 매개 변수가 무시됩니다.
html.beginform 메소드 예제
MVC 뷰 코드
<h1> 온라인 적용 </h1> @using (html.beginform ( "apply", "star", formmethod.post, new {@class = "myform"}))) {<div> <table> <tr> <td> triver type </td> <td>@html.droplistfor (m = typeid, modelod, m.Starmodel.Typeid, modelod. {id = "type", @class = "my-"}) </td> </tr> <tt> <td> 홈 페이지 전문가 사진 </td> <td> <div id = "uploadphoto"> <a href = "javaScript : void (0);"> <span> <em>+</em> 사진을 업로드하십시오. 이름 = "pic"id = "absfileInput"type = "file"/> </a> </div> </td> </td> <tr> <td> </td> <td>@html.hiddenfor (m => m.starmodel.usergravatar, new {id = "sxtphoto"<img src = "id ="id = "img src =" /> </td> </tr> <tr> <td> 자기 권장 이유 </td> <td>@html.textAreafor (m => m.starmodel.applyReason, new {id = "tdesc"}) </td> </tr> <td> <td> <td> <a href = "javascript : id = "btnapplication"> <img src = "@url.content ("~/areving/sns/temes/default/content/images/ap_9.gif ")"/> </a> </a> </td> </table> </div>}2. BeginRouteForm 메소드 (htmlHelper, String, Object, Formmethod)
매개 변수
htmlhelper 유형 : System.Web.mvc.htmlHelper
이 메소드는 HTML 헬퍼 인스턴스를 확장합니다.
라우 티나 이름 유형 : System.String
양식을 게시하는 데 사용되는 경로의 이름은 URL을 게시하는 데 사용됩니다.
RoutEvalues 유형 : System.Object
라우팅 매개 변수를 포함하는 객체. 객체의 특성을 확인함으로써 매개 변수는 반사를 사용하여 검색됩니다. 이 객체는 일반적으로 Object Initializer 구문을 사용하여 생성됩니다.
방법 유형 : System.Web.MVC. Formmethod
양식을 처리하는 데 사용되는 HTTP 방법 (GET 또는 POST).
반환 값
유형 : System.Web.mvc.html.mvcform
시작 <form> 태그.
사용 지침
Visual Basic 및 C#에서이 방법은 유형 htmlhelper의 모든 객체에서 인스턴스 메소드로 호출 될 수 있습니다. 인스턴스 메소드 구문을 사용 하여이 메소드를 호출 할 때 첫 번째 매개 변수를 생략하십시오.
beginrouteform 예제
<div> @using (html.beginrouteform ( "searchPage", new {cityId = model.cityId, productType = model.CurrentProductType, currentPageIndex = model.currentIndex, keyword = model.keyword}, formmethod.get)) <input type = "value" type = "제출"id = "제출"value = "검색">} </div>전통적인 양식 Aciton 속성 제출
HTML 양식의 Aciton 속성을 직접 사용하여 제출하십시오.
방법 예
<form id = "askform"action = "@url.action ("askform ")"메소드 = "post"> <div> <span> </span> <select id = "dplbdttype"name = "dplbdttype"> </select> <select id = "seltype"name = "seltype"> </div> </div>jQuery+ajax 제출 양식
방법 예
섹션을 봅니다
<div id = "postweibo"> <a href = "javaScript : void (0)"> 게시 </a> </div>
jQuery 및 Ajax 부품
// long weibo $ ( "#postweibo"). click (function () {var blogid = $ ( "#hfid"). val (); var title = $ ( "#title"). empty! '); return;} if (title.length> = 40) {showfailtip ( "wibo 제목은 40 단어를 초과 할 수 없습니다!"); return;} // 숫자가 if (isnan (fee)) { "텍스트를 포함 할 수 없음, nutains diswords (title + des)). 단어를 비활성화하십시오. 재검토하십시오! ');} $. ajax ({url : "/fx" + $ maticsoft.basepath + "blog/ajaxupdate",'post ', async : false, datatype :'html ', // timeout : 100000, data : {title : cityid : city, city, cate : tag,, tag,,,, tag. startDate : startDate : EndDate : endDate, imgurl : imgurl, des : des : des, blogid}, // success : function (resultData) {$ ( ". dialogDiv"). {$ .jbox.tip ( 'admin은 작동 할 수 없습니다', 'error');} else {var data = $ (resultData);}});});MVC 컨트롤러 컨트롤러 및 양식 매개 변수 전달
1. 일반 매개 변수
HTML 태그 이름은 매개 변수 이름과 동일합니다.
public actionResult ask (string txttitle, String txteditor, String dplbdttype, String seltype, String txtyzm) {}2. 엔티티 전송
HTML 태그 이름 속성 및 모델 속성은 일관성이 있습니다.
[httppost] public actionResult Apply (ViewModel.sns.star 모델) {// logistic}4. 양식 수집에서 매개 변수를 전송합니다
[httppost] Public ActionResult Apply (FormCollection Form) {// Logistic}위는 편집자가 소개 한 MVC 양식을 제출하는 4 가지 방법에 대한 자세한 설명입니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!