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
source to share
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
});
});
source to share
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.
source to share