Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. <input type="submit" name="submitbutton1" value="submit1" />
  2. <input type="submit" name="submitbutton2" value="submit2" />
  3.  
  4. if( Request.Form["submitbutton1"] != null)
  5. {
  6. // Code for function 1
  7. }
  8. else if(Request.Form["submitButton2"] != null )
  9. {
  10. // code for function 2
  11. }
  12.  
  13. <input id="btnFilterData" type="button" value="myBtn">
  14.  
  15. <script type="text/javascript">
  16. $('#btnFilterData').click(function () {
  17. myFunc();
  18. }
  19. });
  20. </script>
  21.  
  22. function myFunc() {
  23. $.ajax({
  24. type: "GET",
  25. contentType: "application/json",
  26. url: "/myController/myFuncOnController",
  27. data: {
  28. //params, which you can pass to yu func
  29. },
  30. success: function(result) {
  31.  
  32. error: function (errorData) {
  33.  
  34. }
  35. });
  36. };
  37.  
  38. <form action="/Controller_name/action" method="Post>
  39.  
  40. <input type="submit" name="btn1" value="Ok" />
  41. <input type="submit" name="btn1" value="cancel" />
  42. <input type="submit" name="btn1" value="Save" />
  43. </form>
  44.  
  45. string str =Request.Params["btn1"];
  46. if(str=="ok"){
  47.  
  48.  
  49. }
  50. if(str=="cancel"){
  51.  
  52.  
  53. }
  54. if(str=="save"){
  55.  
  56.  
  57. }
  58.  
  59. @using (Html.BeginForm("Action1", "Controller"))
  60. {
  61. <input type="submit" value="Button 1" />
  62. }
  63.  
  64. @using (Html.BeginForm("Action2", "Controller"))
  65. {
  66. <input type="submit" value="Button 2" />
  67. }
  68.  
  69. @using (Html.BeginForm("DliAction", "Dli", FormMethod.Post, new { id = "mainForm" }))
  70. {
  71. if (isOnDli)
  72. {
  73. <button name="removeDli" value="@result.WeNo">Remove From DLI</button>
  74. }
  75. else
  76. {
  77. <button name="performDli" value="@result.WeNo">Perform DLI</button>
  78. }
  79. }
  80.  
  81. public ActionResult DliAction(string removeDli, string performDli)
  82. {
  83. if (string.IsNullOrEmpty(performDli))
  84. {
  85. ...
  86. }
  87. else if (string.IsNullOrEmpty(removeDli))
  88. {
  89. ...
  90. }
  91.  
  92. return View();
  93. }
  94.  
  95. @using (Html.BeginForm("DliAction", "Dli", FormMethod.Post, new { id = "mainForm" }))
  96. {
  97.  
  98. <button name="weNo" value="@result.WeNo">Process This WeNo</button>
  99.  
  100. <button name="weNo" value="@result.WeNo">Process A Different WeNo This Item</button>
  101. }
  102.  
  103. public ActionResult DliAction(string weNo)
  104. {
  105. // Process the weNo...
  106.  
  107. return View();
  108. }
  109.  
  110. @Html.Begin()
  111. {
  112. // Html code here
  113. <input type="submit" name="command" value="submit1" />
  114. <input type="submit" name="command" value="submit2" />
  115.  
  116. }
  117.  
  118. public ActionResult Create(Employee model, string command)
  119. {
  120. if(command.Equals("submit1"))
  121. {
  122. // Call action here...
  123. }
  124. else
  125. {
  126. // Call another action here...
  127. }
  128. }
  129.  
  130. @{
  131. if (IsPost)
  132. {
  133. if(Request["btn"].Equals("button_A"))
  134. {
  135. Response.Redirect("PageA.cshtml");
  136. }
  137. if(Request["btn"].Equals("button_B"))
  138. {
  139. Response.Redirect("PageB.cshtml");
  140. }
  141. }
  142. }
  143. <form method="post">
  144. <input type="submit" value="button_A" name="btn"/>;
  145. <input type="submit" value="button_B" name="btn"/>;
  146. </form>
  147.  
  148. @helper SubmitButton(string text, string cssClass, string controller,string action)
  149. {
  150. var uh = new System.Web.Mvc.UrlHelper(Context.Request.RequestContext);
  151. string url = @uh.Action(action, controller, null);
  152. <div class='@cssClass' onclick="(
  153. function(e)
  154. {
  155. $(e).parent().attr('action', '@url'); //rewrite action url
  156. //create a submit button to be clicked and removed, so that onsubmit is triggered
  157. var form = document.getElementById($(e).parent().attr('id'));
  158. var button = form.ownerDocument.createElement('input');
  159. button.style.display = 'none';
  160. button.type = 'submit';
  161. form.appendChild(button).click();
  162. form.removeChild(button);
  163. }
  164. )(this)">@text</div>
  165. }
  166.  
  167. div.Button {
  168. display: inline-block;
  169. cursor: pointer;
  170. /* Plus colors, padding etc*/
  171. }
  172.  
  173. div.Button:active {
  174. //Just a simple effect to indicate pressing. You might make something different
  175. outline: 1px solid #6BA7B5;
  176. }
  177.  
  178. @Helpers.SubmitButton("Text for 1st button","Button","ControllerForButton1","ActionForButton1")
  179. @Helpers.SubmitButton("Text for 2nd button","Button","ControllerForButton2","ActionForButton2")
  180. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement