2010-08-06 2 views
5

jQuery를 사용하여 양식 데이터를 제출하려고합니다. ASP.NET WebMatrix를 사용하고 있습니다. 내가 가지고있는 .cshtml 파일에서ASP.NET 웹 페이지 (WebMatrix)의 jQuery 게시물

@{ 
    // 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로 다시 응답 할 수 있습니까?

답변

0

값은 jQuery.post()를 통해 Request.Parameters에 전달됩니다.

6

좋은 방법은 jQuery가 전달할 모든 값을 가진 객체를 작성하는 대신 $ (this) .serialize()를 사용하여 양식 데이터를 게시하는 것입니다. 그 다음, yah, Request [ "title"] 등은 게시 된 값을 가져옵니다.

+0

그래, 나중에 너무 것으로 나타났습니다. 어쨌든 고마워! – zigomir