barath thangam
barath thangam

Reputation: 113

ViewModel receives null

Hi am working on a simple form submit in asp.net core 3.1 version. I need to use view model to get data from form. The problem is when I try to submit it, the tax model receives null on controller. Everything seems to be correct but still it receives null.

My viewmodel

enter image description here

My model

enter image description here

My form

enter image description here

My controller

enter image description here

Upvotes: 0

Views: 75

Answers (1)

Yiyi You
Yiyi You

Reputation: 18219

asp.net core bind data with name attribute,try to replace:

    <input type="text" asp-for="Tax.TaxName" class="form-control" id="TaxName" placeholder="Tax Name" />

with

<input type="text" name="tax.Tax.TaxName" class="form-control" placeholder="Tax Name" />

result: enter image description here

Upvotes: 1

Related Questions