Solved

Posting form using anchor tag

Posted on 2012-03-20
7
1,217 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 discusses how to implement server side field validation and display customized error messages to the client.
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…

738 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