我正在尝试在选择列表中设置多个值:
SelectList List = new SelectList(MyListItems, "valField", "dataField", <selected values>);
Run Code Online (Sandbox Code Playgroud)
我用什么对象/值来选择多个项目?
我正在尝试设置id和namefor @Html.EditorFor,但这不起作用:
@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"})
Run Code Online (Sandbox Code Playgroud)
如何设置id和name?
我在这里错过了什么?
视图模型:
public class ViewModel
{
public IDictionary<int, string> Entities { get; set; }
public int EntityId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public override ActionResult Create(string id)
{
ViewModel = new ViewModel();
IEnumerable<Entity> theEntities = (IEnumerable < Entity >)db.GetEntities();
model.Entities= theEntities.ToDictionary(x => x.Id, x => x.Name);
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
视图:
<div class="editor-field">@Html.DropDownListFor(model => model.EntityId,
new SelectList(Model.Entities, "Id", "Name"))</div>
</div>
Run Code Online (Sandbox Code Playgroud)
错误:
DataBinding:'System.Collections.Generic.KeyValuePair ....不包含名为'Id'的属性
我是JSON的新手,并且已经在MVC3 ASP.NET中使用它,但是有人可以了解如何根据JSON结果返回错误吗?
我的观点中有以下电话:
$.ajax({
type: "POST",
dataType: "json",
url: "EditJSON",
data: { FilmID: InputFilmID, Title: InputTitle, Description: InputDescription},
success: function (result) {
alert(result.Message + " updating film " + result.Title);
window.location = "../All";
},
error: function (error) {
alert('error');
}
});
Run Code Online (Sandbox Code Playgroud)
Controller成功处理请求.我将为JSON错误传回什么,以便在View中处理错误:函数?
[AcceptVerbs("POST")]
public JsonResult EditJSON(BobsMoviesMVC2.Models.Film film)
{
filmRepository.Update(film);
return Json(new {Message = "Success", Title = film.Title });
// What would I return for an error here?
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
有人可以提供代码来修复此错误吗?
"无法将带有[]的索引应用于"ICollection"类型的表达式
本质上,我正在尝试从对象集合中保存/绑定值.
@model MVC3.Models.Parent
@Html.EditorFor(model => model.Bs[0].Val)
public class A
{
public int Name { get; set; }
public virtual ICollection<B> Bs { get; set; }
}
public class B
{
public int Val { get; set; }
public virtual A A { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 是否有更好的(更新)替代以下标准onbuttonclick()使用jquery或mvc3助手操作调用javascript函数?
<button onclick="javascript:AddNew()" title="ad action">Add</button>
Run Code Online (Sandbox Code Playgroud) 我有一个模型,我用于将数据从我的视图传递到我的控制器,但我有一些未绑定的文本框和下拉列表.如何使用ViewData或ViewBag等将我的视图中的未绑定数据传递回控制器.谢谢!