ASP.NET网页(WebMatrix)发布的jQuery帖子

时间:2010-08-06 21:26:31

标签: asp.net jquery ajax post webmatrix

我正在尝试使用jQuery提交表单数据。我正在使用ASP.NET WebMatrix。在.cshtml文件中我有

@{
    // 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>

如何将值从表单传递给Request.Form对象?我怎么能比json回复回到HTML?

3 个答案:

答案 0 :(得分:6)

更好的方法是让jQuery使用$(this).serialize()发布表单数据,而不是构建一个包含它的所有值的对象。之后,yah,Request [“title”]等将获得已发布的值。

答案 1 :(得分:2)

答案 2 :(得分:0)

值通过jQuery.post()传递给Request.Parameters。

相关问题