0

I have a purchase form to receive some data according to a model but here my purchase_return object in the controller is not receiving any data. it is receiving productId 0 and productNm null. can anyone point out what is going on here? the html:

<form id="Purchase_ReturnForm">
    <div>
        <table>
            <tr>
                <td>
                    @Html.LabelFor(model => model.ProductId)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.ProductId)
                </td>
                <td>
                    <input type="button" id="btnFind" value="Find" />
                </td>
            </tr>
            <tr>
                <td>
                    @Html.LabelFor(model => model.ProductNm)
                </td>
                <td>
                    <span id="edit">
                        @Html.TextBoxFor(model => model.ProductNm)
                    </span>
                </td>
            </tr>
        </table>
    </div>
</form>  

the script:

 <script>
    $(document).ready(function () {
        $('#btnFind').click(function () {
            var data = $('Purchase_ReturnForm').serialize();
            $.ajax({
                type: 'Post',
                url: '/Purchase_Return/FindProductInvoice',
                data: data,
                success: function () {

                }
            })
        });
    });
</script> 

in controller:

public ActionResult FindProductInvoice(Purchase_Return purchase_Return)
    {
        return View();
    }

And the model

 public class Purchase_Return
{
    //public DateTime ReturnDt { get; set; }
    //public int ReturnSl { get; set; }
    //public DateTime PurchaseDt { get; set; }
    //public int PurchaseSl { get; set; }
    //public double TotReturnAmt { get; set; }
    //public double TotVat { get; set; }
    //public double TotDiscount { get; set; }
    //public int CustomerSupplyId { get; set; }
    [Display(Name="Product")]
    public int ProductId { get; set; }
    public string ProductNm { get; set; }
    //public double PurchaseRt { get; set; }
    //public double PurchaseQty { get; set; }
    //public double ProductDisAmt { get; set; }
    //public double ProductVat { get; set; }
    //public string ReturnNote { get; set; }
    //public int InsertUserId { get; set; }
}

1 Answers1

1

Add # sign in your data cause you are using a id selector to catch the form data.

$('#Purchase_ReturnForm').serialize()

It should work as you expected.

Raihan Ridoy
  • 678
  • 8
  • 18