当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Compiler throws error; generated code missing a bracket

问题描述:

Trying to populate a select list through a view model.

View Model:

public class CountryCity

{

public IEnumerable<SelectListItem> Countries { get; set; }

public SelectList Cities { get; set; }

}

Controller:

public class HomeController : Controller

{

private CountriesContext context = new CountriesContext();

public ActionResult Index()

{

CountryCity cc = new CountryCity();

var countries = from c in context.Countries

orderby c.Name

select c;

cc.Countries = new SelectList(countries,"CountryID", "Name");

return View(cc);

}

}

View:

@using CascadingDropdowns.Models.ViewModels

@model CountryCity

<h2>Index</h2>

<div>

@using (Html.BeginForm())

{

@Html.DropDownList("CountryID", Model.Countries, "Please select country");

@Html.DropDownList("City", new SelectList(string.Empty, "City", "<city>"), "Please select a city", new { @disabled = "disabled" }));

}

</div>

This generates error:

C:\Users\Jakov\AppData\Local\Temp\Temporary ASP.NET Files\root\aad61407\c9799020\App_Web_index.cshtml.a8d08dba.lv9oabqd.0.cs(97,58): error CS1513: } expected

Everything looks fine to me.

网友答案:

You need to remove one of the closing brackets on the below line:

@Html.DropDownList("City", new SelectList(string.Empty, "City", "<city>"), "Please select a city", new { @disabled = "disabled" }));

should be

@Html.DropDownList("City", new SelectList(string.Empty, "City", "<city>"), "Please select a city", new { @disabled = "disabled" });
分享给朋友:
您可能感兴趣的文章:
随机阅读: