views:

1902

answers:

4

I am asp.net-MVC using the BeginForm syntax in my source ciew page and I was told if you want the form to submit you have to have the submit Button at the end of the using statement. I don't want to use a Button to call the desired Action I have an Actionlink set up like so:

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

and I want the form to submit when this actionlink is clicked since they are both going to the same action.. and I don't want to be able to see a Submit button:

  <input type="submit" />

because the link looks better

A: 

What is the question?

style="display:none;" would hide the button. You aren't indicating where you are running into a problem.

Jeff Martin
+4  A: 

I would once again turn to jQuery to handle this task

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

ActionLink is going to produce a hyperlink that you can click on but it won't actually POST the form. You'd need to somehow add the query parameters to the ActionLink if the action is expecting some data to act on. If there is no data to act on, then I don't see a need for a form at all since clicking the link will invoke the action. Presuming that you want just use a link to submit the form, then I don't see why you need an ActionLink at all, nor the input button. Just add a regular anchor tag to the form as below:

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

Note that if you want it to work regardless of javascript being enabled, then you need to be a little more creative. You'd use the button and the link, but start with the button visible and the link hidden. Have a little bit of javascript that runs on document ready that hides the button and shows the link. In this case you could use something similar to what @Corey suggests with the tweak to show the link.

tvanfosson
That's a good call to keep the link hidden and show it with javascript for those users with javascript disabled, otherwise they would see both the link and the button.
Corey Downie
Trying this way I receive an erro saying object doesn't support this method
TStamper
A: 

Javascript would be fine but what I usually do is

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

monmonja