所以我的代码以前工作过.我不知道我为此做了什么,我似乎无法修复它.我见过有人说要重置ModelState.(ModelState.Clear();)但这没有帮助.而且,对于MVC来说,我还是一个新手并没有帮助.任何帮助,将不胜感激.谢谢.
控制器:
public ActionResult Create()
{
ActiveDirectoryModel adm = new ActiveDirectoryModel();
ViewBag.notifyto = adm.FetchContacts();
var model = Populate();
return View(model);
}
[HttpPost]
public ActionResult Create(CreateViewModel model)
{
if (ModelState.IsValid)
{
model.leaf.Date = DateTime.Now.Date;
model.leaf.Category = model.CategoryId;
model.leaf.SubCategory = model.SubCategoryId;
model.leaf.AssignedTo = model.AssignedToId;
model.leaf.CoAssignedTo = model.CoAssignedToId;
model.leaf.Status = model.StatusId;
model.leaf.Priority = model.PriorityId;
//model.lead.Parent = model.ParentID;
db.LeafItems.AddObject(model.leaf);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}
public CreateViewModel Populate()
{
ActiveDirectoryModel adm = new ActiveDirectoryModel();
var model = new CreateViewModel
{
AssignedToItems = adm.FetchContacts(), …Run Code Online (Sandbox Code Playgroud) 所以我正在尝试将外部文件中的纯文本加载到我的页面中,并且我一直在标题中收到错误.我究竟做错了什么?(我完全按照教程!)谢谢.
HTML
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="ajax.js"></script>
</head>
<body>
<input id="button" type="button" value="Load" />
<div id="content"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JQuery的
$("#button").click(function(){
$.ajax({
url:"AjaxRequest.html",
success:function(data) {
$("#content").html(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
编辑:显然没有成功.不知道为什么,文件紧挨着它.
我正在尝试在我的视图中填充下拉列表.任何帮助是极大的赞赏.谢谢.
错误:
无法将类型"System.Int32"强制转换为"System.Object"类型.
LINQ to Entities仅支持转换实体数据模型基元类型.
控制器:
ViewBag.category = (from c in new IntraEntities().CategoryItems
select new SelectListItem() {Text=c.Name, Value=""+c.ID }).ToList<SelectListItem>();
Run Code Online (Sandbox Code Playgroud)
视图:
Category:<br />@Html.DropDownList("category", (List<SelectListItem>)ViewBag.category)
Run Code Online (Sandbox Code Playgroud)