如何通过Web api控制器和jquery ajax在网站页面中发布数据

时间:2018-10-29 19:53:36

标签: asp.net-web-api2

大家好,我在网站上发布数据时遇到的问题是,当我使用mvc表单发布方法时,它运行良好,但是当我使用jquery ajax时,它给了我相同的html表单,其值由我制作api控制器 我的MVC表单提交发布方法代码不正确

@model MakeAnOrder.Models.PaymentDetails

@{
    ViewBag.Title = "Demo";
}

<h2>PayUMoney Form MVC</h2>
@using (Html.BeginForm("CheckPay", "CheckPay", FormMethod.Post))
{
    <div style="margin-left:20px">
        @Html.Label("Amount")<br />
        @Html.TextBox("txtamount")<br />
        @Html.Label("First Name")<br />
        @Html.TextBox("txtfirstname")<br />
        @Html.Label("Email Id")<br />
        @Html.TextBox("txtemail")<br />
        @Html.Label("Product Information")<br />
        @Html.TextArea("txtprodinfo")<br />
        @Html.Label("Phone")<br />
        @Html.TextBox("txtphone")<br />
        @Html.Label("Success URL")<br />
        @Html.TextBox("txtsurl")<br />
        @Html.Label("Failure URL")<br />
        @Html.TextBox("txtfurl")<br /><br />

        <button type="submit">Submit</button>
    </div>
}

以上代码运行良好,并在网站上发布了数据 但是当我使用具有相同控制器代码的休闲代码时,它在html中给出了一些响应,代码休闲了

   $.ajax(
         {
             type: "POST", //HTTP POST Method  
             url: "http://localhost:50371/CheckPay/CheckPay", // Controller/View   
             data:
                 {

                 amount:Amount ,
                 firstName:FirstName ,
                 phone:Phone ,
                 email:Email ,
                 productDetails:ProductDetails 

             },

             dataType: "html",
             //success: function (result) {
             //    alert(result);
             //         alert("successs");
             //         alert(result.responseText);


             //         //}

             //     },
             //     error: function (result) {
             //         alert(result.responseText);
             //         alert("Error");
             //     }





         });

以上给出html响应的代码未发布数据,请帮助我,我有需要

0 个答案:

没有答案