Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Posting form using anchor tag

Posted on 2012-03-20
7
1,212 Views
Last Modified: 2012-08-14
Hi,

I am using the following to post the form:

 @using (Ajax.BeginForm("SendMessage", "User", null,
                                    new AjaxOptions
                                    {
                                        HttpMethod = "POST",
                                        OnSuccess = "jsMessageSent"
                                    })) {
<input placeholder="Message Subject" class="msg-subject" name="subject" />
 <input type="submit" value="Send" class="send-message" onclick="jsCloseComposeMessage();" />}


BUT I want to post this form using anchor tag instead of input type submit

I tried

 @Ajax.ActionLink("testing_Send", "SendMessage", "User", new { subject ="dines"}, new AjaxOptions { HttpMethod = "POST" })

but its becomes querystring.

Please note that I don't want to change my way of implementing ajax i.e Ajax.BeginForm
because it has been  implemented on various places on the project.

Please help!

regards
meetDinesh
0
Comment
Question by:Dinesh Kumar
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37745943
make it (assuming that link id is testing_Send)

$("#testing_Send").attr("href", "javascript:postForm()");

postForm()
{
 $.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: "html"
});
}
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37745950
check this link too
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

it tells how to submit a form using jquery post without refreshing the page
0
 

Author Comment

by:Dinesh Kumar
ID: 37746204
you are right but this solution does not use

Ajax.BeginForm
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Accepted Solution

by:
Dinesh Kumar earned 0 total points
ID: 37746649
one of my colleagues, Amit,  sorted out this the following way:
   <div class="msg-rply-container">
                        <input type="submit" value="Send" class="send-message" />                      
                        <a href="javascript:postMessage();">testing_Send</a>
                    </div>
                    <script language="javascript" type="text/javascript">
                        function postMessage() {
                            $("#SendMessage9").submit(); //submits the form
                            jsCloseComposeMessage();
                        }
                    </script>

its working cool in all browsers. thanks Amit.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37746685
but you are not using "Ajax.BeginForm" here also!!
0
 

Author Comment

by:Dinesh Kumar
ID: 37746835
The complete code is:

            <div class="abc">
                @using (Ajax.BeginForm("actionName", "User", null,
                                    new AjaxOptions
                                    {
                                        HttpMethod = "POST",
                                        OnSuccess = "ok"

                                    }, new { id = "SendMessage9" }))
                {
                    <div class="popup-top-container">
                        <div class="popup-prodetails">
                            <div class="top-txt">
                                Messaging to:</div>
                            <div class="msg-container">
                                <input type="text" class="userid" name="receiver" placeholder="Type your Friends Names Here" />
                                <div class="user-select-opt">                
                  </div>
                            </div>
                        </div>
                        <div class="popup-cancel-btn">
                            <input type="button" value="CANCEL" onclick="jsCloseComposeMessage();" class="popup-cancel2" />
                        </div>
                    </div>
                    <div>
                        <input placeholder="Message Subject" class="msg-subject" name="subject" />
                    </div>
                 
                    <div class="msg-rply-container">
                        <input type="submit" value="Send" class="send-message" />                      
                        <a href="javascript:postMessage();">Checking</a>
                    </div>
                    <script language="javascript" type="text/javascript">
                        function postMessage() {
                            $("#SendMessage9").submit();
                            jsCloseComposeMessage();
                        }
                    </script>
                }
            </div>
0
 

Author Closing Comment

by:Dinesh Kumar
ID: 37764906
This solution worked well.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question