Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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
- }
- <input id="btnFilterData" type="button" value="myBtn">
- <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) {
- }
- });
- };
- <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"){
- }
- @using (Html.BeginForm("Action1", "Controller"))
- {
- <input type="submit" value="Button 1" />
- }
- @using (Html.BeginForm("Action2", "Controller"))
- {
- <input type="submit" value="Button 2" />
- }
- @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();
- }
- @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();
- }
- @Html.Begin()
- {
- // Html code here
- <input type="submit" name="command" value="submit1" />
- <input type="submit" name="command" value="submit2" />
- }
- public ActionResult Create(Employee model, string command)
- {
- if(command.Equals("submit1"))
- {
- // Call action here...
- }
- else
- {
- // Call another action here...
- }
- }
- @{
- 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>
- @helper SubmitButton(string text, string cssClass, string controller,string action)
- {
- var uh = new System.Web.Mvc.UrlHelper(Context.Request.RequestContext);
- string url = @uh.Action(action, controller, null);
- <div class='@cssClass' 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)">@text</div>
- }
- div.Button {
- display: inline-block;
- cursor: pointer;
- /* Plus colors, padding etc*/
- }
- div.Button:active {
- //Just a simple effect to indicate pressing. You might make something different
- outline: 1px solid #6BA7B5;
- }
- @Helpers.SubmitButton("Text for 1st button","Button","ControllerForButton1","ActionForButton1")
- @Helpers.SubmitButton("Text for 2nd button","Button","ControllerForButton2","ActionForButton2")
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement