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

旧城冷巷雨未停 提交于 2019-12-02 01:59:30

You need to set the name attribute in your html element:

<input type="text" id="txtbox2" name="txtbox2" />

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!