Answer the question
In order to leave comments, you need to log in
Why does books[i] become null?
I have a view for an Account controller with a link:
@helper BookList(List<App.Models.Book> books){
for (int i = 0; i < books.Count; i++){
<td>@Html.ActionLink(books[i].Name, "Open", "Description", books[i] , null)</td>
<td>@books[i].Author</td>
}
}
public string Open(List<App.Models.Book> book)
{
if(book == null)
{
return "Не выбрана";
}
return "Выбрана";
}
<td>@Html.ActionLink(books[i].Name, "Open", "Description", books[i] , null)</td>
<td>@Html.ActionLink(books[i].Name, "Open", "Description", new { book = books[i] } , null)</td>
//сигнатуру метода также менял, не помогает
public string Open(Book book)
Answer the question
In order to leave comments, you need to log in
Because Open expects you to link to the entire list of books, not to a specific book. If the whole list is needed there, pass it + the index of the desired book.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question