我试图用jQuery提交表单数据。我使用ASP.NET WebMatrix中。在一个.cshtml文件I有

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

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

其他提示

一个更好的方式是只具有jQuery的后使用$(本).serialize()而不是建立一个对象在它的所有值之在通过表单数据。在此之后,严,请求[“标题”]等将得到被张贴的值。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top