Object reference not set to instance of an object while getting data from request object/Formcollection

前端 未结 2 628
我寻月下人不归
我寻月下人不归 2021-01-22 05:00

i am trying to implement a simple add operation using MVC Ajax

My code is as follows:

Public Class Model

{
  public int number1{get;set;}

  public int          


        
2条回答
  •  醉话见心
    2021-01-22 05:26

    Update: Based on your model:

    [HttpPost]
    public int TestAjax(Model mymodel)
    {
      return mymodel.number1 + mymodel.number2;
    }
    

    And in your HTML assuming you are referencing the model:

    @model Model
    

    replace your inputs with this accordingly:

    @Html.TextBoxFor(model => model.number1)
    @Html.TextBoxFor(model => model.number2)
    

    You have to validate that the user only types integer valid values in your textboxes with javascript.

提交回复
热议问题