在实现方面,我应该如何选择基本类型或接口?我尝试了几个例子,但我没有得到完整的想法:(
关于如何以及为什么的例子将受到高度赞赏..
我试图将DropDownListFor帮助器与控制器中定义的viewbag绑定.但我收到了错误.
查看代码: -
@Html.DropDownListFor(model => model.CurrencyID, ViewBag.CurrencyList as SelectListItem))
Run Code Online (Sandbox Code Playgroud)
控制器代码: -
public ActionResult Create()
> {
> var content = from p in db.Currency
> where p.IsActive == true
> orderby p.CurrencyName
> select new { p.CurrencyID, p.CurrencyCode };
>
> var x = content.ToList().Select(c => new SelectListItem
> {
> Text = c.CurrencyCode,
> Value = c.CurrencyID.ToString(),
> Selected = (c.CurrencyID == 68)
> }).ToList();
> ViewBag.CurrencyList = x;
>
> return View();
> }
Run Code Online (Sandbox Code Playgroud)
收到错误: - System.Web.Mvc.HtmlHelper'不包含'DropDownListFor'的定义和最佳扩展方法重载'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper,System. Linq.Expressions.Expression>,System.Collections.Generic.IEnumerable)'有一些无效的参数
我有一个使用自动完成功能实现的文本框.就这个.
<input id="txtcity" />
$("#txtcity").autocomplete({
source: function (request, response) {
$.ajax({
url: '@Url.Action("CityLookup", "PatientDemographic", "")', type: "POST", dataType: "json",
data: { searchText: request.term, maxResults: 10 },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Text, value: item.Text, id: item.Value }
}))
}
})
},
select: function (event, ui) {
$("#CityCode").val(ui.item.id);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
Run Code Online (Sandbox Code Playgroud)
这会返回三个结果,比如说"Apple","Banana","Cabbage".如何在渲染时将默认值设置为"Banana"?即,text ="banana"value ="2"?
我刚刚按照此链接中的说明创建了一个新的 NServiceProject:
但是在运行项目后,我收到以下错误
"No destination specified for message(s):".
我不确定我哪里出错了。
我已经创建了 ASP.NET MVC 类型的项目。