我一直在关注这个教程http://blogs.msdn.com/b/stuartleeks/archive/2010/05/21/asp-net-mvc-creating-a-dropdownlist-helper-for-enums.aspx但我跑了进入错误"System.Web.Mvc.HtmlHelper不包含EnumDropDownListFor的定义".
模型:
public enum Codes
{
IBC2012,
IBC2009,
IBC2006,
FL2010,
CBC2007
}
public class Code
{
public int ID { get; set; }
public int Active { get; set; }
public string Description { get; set; }
public string Edition { get; set; }
public Codes Code { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public static MvcHtmlString EnumDropDownListFor<TModel, TEnum>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TEnum>> expression)
{
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
IEnumerable<TEnum> values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
IEnumerable<SelectListItem> items =
values.Select(value => …Run Code Online (Sandbox Code Playgroud) 我是mvc C#的新手,我被卡住了.请告知如何解决这个问题.我在Add上收到错误.当我将鼠标悬停在红色波浪线上时,它会显示"并非所有代码路径都返回值"
public ActionResult Add(ShapeInputModel dto, FormCollection collection)
{
var model = new GeoRegions();
if (TryUpdateModel(model))
{
var destinationFolder = Server.MapPath("/App_Data/KML");
var postedFile = dto.Shape;
if (postedFile != null)
{
var fileName = Path.GetFileName(postedFile.FileName);
var path = Path.Combine(destinationFolder, fileName);
postedFile.SaveAs(path);
//Save to Database
Db.AddGeoRegions(model);
return RedirectToAction("Index");
}
return View();
}
}
Run Code Online (Sandbox Code Playgroud)