Solved

Posting form using anchor tag

Posted on 2012-03-20
7
1,205 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now