Solved

Posting form using anchor tag

Posted on 2012-03-20
7
1,210 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

776 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