0

I am attempting to call a function through a view using jquery.. originally i was using razor's @html.BeignForm but for the web it needs to be converted to jquery

i don't know if i'm on the right path, however this is what i have in razor that's currently working.

@foreach(var up in Model)
{
    @up._id

    using (@Html.BeginForm("DQPost", "Disqus", new { ID = up._id }, FormMethod.Post))
    {
        <h7>The thread ID</h7>
        <input type="text" name="ThreadID" /><br />
        <h7>The message&nbsp;</h7>
        <input type="text" name="Message" /><br />
        <input type="submit" value="Post Comment"/>
    }
}

what i'm trying to do is change the submit to button that then fires off the jquery. and this is the jquery i currently have written out.

<script type="text/javascript">
    $(document).ready(function () {
        $('#post').click(function () {
            var dataToSend = { ID: ID, MethodName: 'DQPost', Message: message };

            var options =
            {
                data: dataToSend,
                dataType: 'JSON',
                type: 'POST',
            }
        });
    });

 </script>

any help would be greatly appreciated.

2 Answers 2

1

You are wrong here,$('#post').

  $('#post').click(function () {

Post is not an identifier., so, you could declare your own. You could try something like

<input type="submit" id="submitButton" value="Post Comment"/>

Then,

 $('#submitButton').click(function () {

will work fine.

Sign up to request clarification or add additional context in comments.

2 Comments

okay that would be correct about the $('submitButton').click(function(){ however i am looking to replace the razor code all together so would this essentially do that?
@user2448701 - What's the point of removing razor? What do you plan to generate the client HTML with and why?
0

Looks like you want to intercept the form submission so you can handle submit yourself with AJAX. If I'm reading that right, instead of attaching to the button's event, attach to the form's event:

$("#my-form-id").submit(function() {
    // do my AJAX stuff
    return false; // this will prevent the form from being submitted like normal
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.