【发布时间】:2015-09-02 06:57:20
【问题描述】:
我可以将纬度、经度、邻居和邻居限制变量发送到 View。但是,我想从视图中更改邻居限制。当我发布 View 时,MapViewModel 的变量为 0,我试过 ModelState.Clear() 但没有区别,你能帮我吗?谢谢
型号:
public class MapViewModel
{
public double lat;
public double lon;
public List<Point> neighbors;
public Polygon polygon;
public int neighborlimit;
public double[][] polyTable;
}
控制器:
[HttpGet]
public ActionResult Map()
{
UserAccount user = (UserAccount)UserManager.FindByName(User.Identity.Name);
MapViewModel model = new MapViewModel() { lat = (double)user.address.latitude, lon = (double)user.address.longitude, neighbors = user.getNeighbors(), neighborlimit= (int)user.neighborsLimit };
return View(model);
}
[HttpPost]
public ActionResult Map(MapViewModel model)
{
UserAccount user = (UserAccount)UserManager.FindByName(User.Identity.Name);
user.neighborsLimit = model.neighborlimit;
UserManager.Update(user);
return View(model);
}
查看:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-group">
<div class="col-md-10">
@Html.TextBoxFor(h => h.neighborlimit, new { @class = "form-control" })
</div>
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
}
【问题讨论】:
标签: asp.net-mvc razor http-post