I'm following a book about C# (Pro asp.net MVC 3 Framework) It is a little out dated but there's not much difference compared to the newer versions.
Ebook: Ebook version, google link. I have the paper version of the book, but the page numbering is the same. I got stuck at page 205, it asks me to create a view named 'Menu' and with the model class IEnumerable<string>
I can't create that, when I enter that I cannot click on 'ADD'
According to the book:
According to my editor:
I'm new to C# but I'll paste some of my code to let you guys understand it better.
{
public class NavController : Controller
{
private IProductRepository repository;
public NavController(IProductRepository repo)
{
repository = repo;
}
public PartialViewResult Menu() //Krijg hier geen VIEW met: "IEnumerable<string>" als Modelclass.
{
IEnumerable<string> categories = repository.Products
.Select(x => x.Category)
.Distinct()
.OrderBy(x => x);
return PartialView(categories);
}
}
}
Hopefully it's just something silly I did wrong.
Tips&adjustments are welcome!
Best regards
You can simply create a view then specify the Model
:
@model IEnumerable<string>
@foreach (var str in Model)
{
<li>
@Html.LabelFor(m => str, "My Label")
@Html.TextBoxFor(m => str)
@Html.ValidationMessageFor(m => str)
</li>
}
So as Stephen mentioned there's no need to specify the modal that way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.