3 개 안에 있는 자르기 보기입니다 곷떒 양식. # 39 의 작업은 기본적으로 필요한 모든 button& 양식 값이 나올 수 있는 입력 값 보다 작은 자연수이다.
버튼 누르면 그 때마다 나는 리디렉션된 나에게 기본 동작. 제발 안내선 내가 어떻게 전송할 수 있는 다양한 동작을 양식을 기반으로 단추 누름에?
정말 고맙게 생각할 시간, 안내 및 움말.
이 시도할 수도 있습니다.
<input type="submit" name="submitbutton1" value="submit1" />
<input type="submit" name="submitbutton2" value="submit2" />
그 후 해당 기능을 기본 기능 전화하시기 운영까지도:
if( Request.Form["submitbutton1"] != null)
{
// Code for function 1
}
else if(Request.Form["submitButton2"] != null )
{
// code for function 2
}
이 우아한 솔루션이므로 수에 대한 작동됨 제출됩니다 버튼:
@Html.Begin()
{
// Html code here
<input type="submit" name="command" value="submit1" />
<input type="submit" name="command" value="submit2" />
}
또한 너회의 controllers& # 39. 그 방법을 작업이든지 동의하십시오 매개변수입니다.
public ActionResult Create(Employee model, string command)
{
if(command.Equals("submit1"))
{
// Call action here...
}
else
{
// Call another action here...
}
}
뷰에서의
<form action="/Controller_name/action" method="Post>
<input type="submit" name="btn1" value="Ok" />
<input type="submit" name="btn1" value="cancel" />
<input type="submit" name="btn1" value="Save" />
</form>
에서 작업
string str =Request.Params["btn1"];
if(str=="ok"){
}
if(str=="cancel"){
}
if(str=="save"){
}
Js + 아약스 사용할 수 있습니다. 예를 들어, 버튼을 클릭하면 무슨 의미가 있다고 말할 수 있는 경우 이벤트 수행해야 할 수 있습니다. 이 코드:
<input id="btnFilterData" type="button" value="myBtn">
여기서 html 의 너회의 버튼를. 이 코드는 스크립트에서 사용하는 데 필요한 부분 (이 섹션은 문서 끝에):
<script type="text/javascript">
$('#btnFilterData').click(function () {
myFunc();
});
</script>
마지막으로, 아약스 기능을 추가해야 합니다 (섹션, 있어야 할 또 다른 스크립트입니다 태초 영안실에 문서의):
function myFunc() {
$.ajax({
type: "GET",
contentType: "application/json",
url: "/myController/myFuncOnController",
data: {
//params, which you can pass to yu func
},
success: function(result) {
error: function (errorData) {
}
});
};
이 예는 두 개의 매우 다른 작업을 수행할 수 있습니다. 기본 전제는 < button>, 사용할 수 있다. 데이터를 전달하는 데 가치를 작업.
In your 보기:
@using (Html.BeginForm("DliAction", "Dli", FormMethod.Post, new { id = "mainForm" }))
{
if (isOnDli)
{
<button name="removeDli" value="@result.WeNo">Remove From DLI</button>
}
else
{
<button name="performDli" value="@result.WeNo">Perform DLI</button>
}
}
그럼 내 작업:
public ActionResult DliAction(string removeDli, string performDli)
{
if (string.IsNullOrEmpty(performDli))
{
...
}
else if (string.IsNullOrEmpty(removeDli))
{
...
}
return View();
}
이를 위해 이 코드를 변경할 수 있어야 한다 (예: # 39 의 이름을 따라 변형이 search. button& 변경하십시오 같아야 관심용 작업에 따라 등을 볼 수 있듯이 하나의 매개변수입니다 됩니다 (아래 참조).
In your 보기:
@using (Html.BeginForm("DliAction", "Dli", FormMethod.Post, new { id = "mainForm" }))
{
<button name="weNo" value="@result.WeNo">Process This WeNo</button>
<button name="weNo" value="@result.WeNo">Process A Different WeNo This Item</button>
}
그럼 내 작업:
public ActionResult DliAction(string weNo)
{
// Process the weNo...
return View();
}
정상 (비사양 제출) 버튼을 사용할 수 있습니다. (# 39, & # 39, onclick& 열린 재작성할 javascript 를 사용하여 # 39, & # 39 의 이벤트) 이 form& action& # 39. 그 후 귀의한다면 속성을 바라요. 버튼을 사용하여 발령합니다 사용자 정의 도우미 (파일 작성 " Helper.cshtml"; 이 프로젝트의 App_Code 폴더에서는 인사이드라면 루트에).
@helper SubmitButton(string text, string controller,string action)
{
var uh = new System.Web.Mvc.UrlHelper(Context.Request.RequestContext);
string url = @uh.Action(action, controller, null);
<input type=button onclick="(
function(e)
{
$(e).parent().attr('action', '@url'); //rewrite action url
//create a submit button to be clicked and removed, so that onsubmit is triggered
var form = document.getElementById($(e).parent().attr('id'));
var button = form.ownerDocument.createElement('input');
button.style.display = 'none';
button.type = 'submit';
form.appendChild(button).click();
form.removeChild(button);
}
)(this)" value="@text"/>
}
그리고 이를 사용할 수 있다.
@Helpers.SubmitButton("Text for 1st button","ControllerForButton1","ActionForButton1")
@Helpers.SubmitButton("Text for 2nd button","ControllerForButton2","ActionForButton2")
...
Δ1 양식에.
가장 간단한 방법은 list. 포르막션 포르마토드 'html5' '와'
<input type="submit"
formaction="Save"
formmethod="post"
value="Save" />
<input type="submit"
formaction="SaveForLatter"
formmethod="post"
value="Save For Latter" />
<input type="submit"
formaction="SaveAndPublish"
formmethod="post"
value="Save And Publish" />
[HttpPost]
public ActionResult Save(CustomerViewModel model) {...}
[HttpPost]
public ActionResult SaveForLatter(CustomerViewModel model){...}
[HttpPost]
public ActionResult SaveAndPublish(CustomerViewModel model){...}
여러 가지 다른 방법으로 사용할 수 있는 문서, 우리는 이 슬라이드에서는 여러 다른 방식으로 사용하는 아스피네 MVC 제출됩니다 버튼를
이것은 어떤 방법이 주효했는가 for me.
formaction="@Url.Action("Edit")"
스니핏:
<input type="submit" formaction="@Url.Action("Edit")" formmethod="post" value="Save" class="btn btn-primary" />
<input type="submit" formaction="@Url.Action("PartialEdit")" formmethod="post" value="Select Type" class="btn btn-primary" />
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit( Quote quote)
{
//code
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult PartialEdit(Quote quote)
{
//code
}
도움이 될 수 있는 방법 중 하나가 아닌 두 개의 서로 다른 작업을 일부 who wants to 사용한 방법을 선택기를 또는 클라이언트를 사용하여 스크립트입니다.
이 대답 (asp.net) 와 함께 제어할 수 있는 방법을 안내해 드리죠 작업하십시오 자르기, 여러 제출] 이벤트. 예를 들어 1, 2 버튼, 하나님이 우리에게 비헤이비어는 리디렉션할 버튼은 " PageA.cshtml". 및 기타 는 우리에게 PageB.cshtml" 리디렉션하십시오 ";).
@{
if (IsPost)
{
if(Request["btn"].Equals("button_A"))
{
Response.Redirect("PageA.cshtml");
}
if(Request["btn"].Equals("button_B"))
{
Response.Redirect("PageB.cshtml");
}
}
}
<form method="post">
<input type="submit" value="button_A" name="btn"/>;
<input type="submit" value="button_B" name="btn"/>;
</form>
< /form>;
Html 의.
<form action="" method="post" role="form">
<table>
@for (var i = 0; i < Model.List.Count(); i++)
{
<tr>
<td>@Model.List[i].ItemDescription</td>
<td>
<input type="submit" value="REMOVE" class="btn btn-xs btn-danger"
asp-controller="ControllerName" asp-action="delete" asp-route-idForDeleteItem="@Model.List[i].idForDeleteItem" />
</td>
</tr>
}
</table>
</form>
켜짐이 컨트롤러거:
[HttpPost("[action]/{idForDeleteItem}"), ActionName("Delete")]
public async Task<IActionResult> DeleteConfirmed(long idForDeleteItem)
{
///delete with param id goes here
}