JQuery post from ASP.NET webpage (WebMatrix)

I am trying to submit form data using jQuery. I am using ASP.NET WebMatrix. In the .cshtml file I have

@{
    // other code
    if(IsPost)
    {
        var item = new Item();
        item.Title = Request.Form["title"];
        item.Description = Request.Form["description"];

        // aditional code here
    }
}
<script type="text/javascript">
    $(document).ready(function(){
        $("form#itemForm").submit(function(){
            $.post("form.cshtml", {
                    title: $("#title").val(), 
                    description: $("#description").val(), 
                    price: $("#price").val()},
                    function(data){
                    },
                    "json");
        })
    });
</script>
<form>
<!-- html form here -->
</form>

How to pass values ​​from a form to a Request.Form object? And how can I than answer from json to html?

+5
source share
3 answers

Values ​​are passed through jQuery.post () to Request.Parameters.

0
source

It would be best to just add jQuery form data using $ (this) .serialize () instead of creating an object with all the values ​​it needs to pass. After that, yah, Request ["title"], etc. Receive the values ​​that were sent.

+6

All Articles