Hide the Submit button for a form

I am asp.net-MVC using the BeginForm syntax in my original ciew page and I was told if you want the form to be submitted, you must have a submit button at the end of the using statement. I don't want to use a button to trigger the desired action. I have an Actionlink configured like this:

  <%=Html.ActionLink("" + CreateMore, "Create", "", new { @class = "Create" })%>

      

and I want the form to be submitted when this actionlink is clicked as they both go to the same action .. and I don't want to see the Submit button:

  <input type="submit" />

      

because the link looks better

+1


source to share


4 answers


I would turn to jQuery again for this task



$(function(){
  $('input:submit').hide(); //hide the submit button
  $('#submitLinkID').click(function(){  // bind the link click event
    $('input:submit').click(); //click the hidden button
    return false; //return false to stop the link from doing anything
  });
});

      

+5


source


What's the question?



not

style = "display: no;" will hide the button. You do not indicate where you encountered the problem.

+3


source


ActionLink is going to create a hyperlink that you can click, but it won't actually POST. You need to add the request parameters to the ActionLink somehow if the action expects some data to act. If there is no data to work with, then I see no need for a form at all, since clicking on the link will trigger an action. Assuming you just want to use a link to submit the form, I don't understand why you need an ActionLink or an enter button at all. Just add a regular anchor tag to your form as shown below:

<a id='submitIDLink'
   href='javascript:void(0);'
   onclick='document.forms[0].submit();'>Create</a>

      

Please note, if you want it to work regardless of the javascript enabled, you need to be a little more creative. You should use a button and a link, but start with a visible button and a hidden link. You have a little javascript running on a rendered document that hides the button and shows the link. In this case, you can use something similar to what @Corey suggests with a customization to show the link.

+1


source


Javascript will be fine, but I usually do this


style = "position: absolute; top: -5000px" will hide the button at the top of the screen, so if just adjust the number if your form is too long.

+1


source







All Articles