Stanley Manoto

Stanley Manoto

  • NA
  • 2
  • 553

{"Object reference not set to an instance of an object."}

Nov 15 2017 3:10 AM
My View
 -----------
 <div class="form-group">
@Html.LabelFor(model => model.PhysicalAddr, htmlAttributes: new { @class = "control-label", @style = "margin-left:10px; float:left;" })
<div>
@Html.EditorFor(model => model.PhysicalAddr, new { htmlAttributes = new { @class = "form-control", @style = "margin-left:150px;" } })
@Html.ValidationMessageFor(model => model.PhysicalAddr, "", new { @style = "color:red;!important; margin-left:150px;" })
</div>
</div>
 
model
--------------
  public class PersonModel
{
public PersonModel()
{
marketService = new MarketModel();
//regionService = new RegionModel();
Region = new List<RegionModel>();
}
[Required]
[Display(Name = "Region")]
public int RegionId { get; set; }
public List<RegionModel> Region { get; set; }
}
 
 
Controller
-------------
public List<RegionModel> GetRegionList()
{
var list = regionService.GetRegions();
List<RegionModel> regionList = new List<RegionModel>();
int tableRow = Convert.ToInt32(list.Tables.Count);

for (int i = 0; i < tableRow; i++)
{
foreach (DataRow dr in list.Tables[i].Rows)
{
regionList.Add(new RegionModel
{
RegionId = Convert.ToInt32(dr["RegionId"]),
RegionName = Convert.ToString(dr["RegionName"]),
State = Convert.ToString(dr["State"]),
ZipCode = Convert.ToInt32(dr["ZipCode"])
});
}
}
return regionList;
 
 

Answers (1)