MVC 자르기 함께 양식을 다양한 전송 버튼?

3 개 안에 있는 자르기 보기입니다 곷떒 양식. # 39 의 작업은 기본적으로 필요한 모든 button& 양식 값이 나올 수 있는 입력 값 보다 작은 자연수이다.

버튼 누르면 그 때마다 나는 리디렉션된 나에게 기본 동작. 제발 안내선 내가 어떻게 전송할 수 있는 다양한 동작을 양식을 기반으로 단추 누름에?

정말 고맙게 생각할 시간, 안내 및 움말.

질문에 대한 의견 (5)
해결책

이 시도할 수도 있습니다.

<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
}
해설 (3)

이 우아한 솔루션이므로 수에 대한 작동됨 제출됩니다 버튼:

@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...
    }
}
해설 (12)

뷰에서의

해설 (0)

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) {

        }
    });
};
해설 (1)

39 의 깨끗한 솔루션이므로 I&, ve 늑대굴에서 다음과 같습니다.

이 예는 두 개의 매우 다른 작업을 수행할 수 있습니다. 기본 전제는 &lt button&gt, 사용할 수 있다. 데이터를 전달하는 데 가치를 작업.

In your 보기:

@using (Html.BeginForm("DliAction", "Dli", FormMethod.Post, new { id = "mainForm" }))
{
    if (isOnDli)
    {
        Remove From DLI
    }
    else
    {
        Perform DLI
    }
}

그럼 내 작업:

    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" }))
{

        Process This WeNo

        Process A Different WeNo This Item
}

그럼 내 작업:

    public ActionResult DliAction(string weNo)
    {
        // Process the weNo...

        return View();
    }
해설 (0)

39 의 고유한 형태로, 각 단추가 랩할 시도하시겠습니까 it& 너회의 보기입니다.

  @using (Html.BeginForm("Action1", "Controller"))
  {
    <input type="submit" value="Button 1" />
  }

  @using (Html.BeginForm("Action2", "Controller"))
  {
    <input type="submit" value="Button 2" />
  }
해설 (1)

정상 (비사양 제출) 버튼을 사용할 수 있습니다. (# 39, & # 39, onclick& 열린 재작성할 javascript 를 사용하여 # 39, & # 39 의 이벤트) 이 form& action& # 39. 그 후 귀의한다면 속성을 바라요. 버튼을 사용하여 발령합니다 사용자 정의 도우미 (파일 작성 &quot 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 양식에.

해설 (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 제출됩니다 버튼를

해설 (0)

이것은 어떤 방법이 주효했는가 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 사용한 방법을 선택기를 또는 클라이언트를 사용하여 스크립트입니다.

해설 (1)

39 순결케 사용하는 경우, 자르기, 즉 안춥단다 MVC 컨트롤러거 you& re:

Hello
World
@if (IsPost)
{
    <p>@Request.Form["SubmitForm"]</p>
}

안녕하세요, 세계 각 버튼을 클릭하면 렌더링합니다 아웃해야 한다.

해설 (1)

이 대답 (asp.net) 와 함께 제어할 수 있는 방법을 안내해 드리죠 작업하십시오 자르기, 여러 제출] 이벤트. 예를 들어 1, 2 버튼, 하나님이 우리에게 비헤이비어는 리디렉션할 버튼은 &quot PageA.cshtml&quot. 및 기타 는 우리에게 PageB.cshtml&quot 리디렉션하십시오 ";).

@{
  if (IsPost)
    {
       if(Request["btn"].Equals("button_A"))
        {
          Response.Redirect("PageA.cshtml");
        }
      if(Request["btn"].Equals("button_B"))
        {
          Response.Redirect("PageB.cshtml");
        }
  }
}

   <input type="submit" value="button_A" name="btn"/>;
   <input type="submit" value="button_B" name="btn"/>;          

&lt /form>;

해설 (3)

39, t 지켜보리니 didn& 답을 알고 (Core MVC), 이제 이 태그를 사용하여 댁이라면 (for a 삭제 작업을):

Html 의.


<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>

켜짐이 컨트롤러거:

[HttpPost("[action]/{idForDeleteItem}"), ActionName("Delete")]
public async Task DeleteConfirmed(long idForDeleteItem)
{
    ///delete with param id goes here
}

39, 't forget don& 사용하기 전에 [라우트를 (&quot "; [컨트롤러])]' 클래스 선언에 대한 - 컨트롤러입니다.

해설 (0)