У меня есть контроллер под названием AuctionsController.В нем есть Действия с именами Index () и AuctionCategoryListing ():
//Used for displaying all auctions.
public ActionResult Index()
{
AuctionRepository auctionRepo = new AuctionRepository();
var auctions = auctionRepo.FindAllAuctions();
return View(auctions);
}
//Used for displaying auctions for a single category.
public ActionResult AuctionCategoryListing(string categoryName)
{
AuctionRepository auctionRepo = new AuctionRepository();
var auctions = auctionRepo.FindAllAuctions()
.Where(c => c.Subcategory.Category.Name == categoryName);
return View("Index", auctions);
}
Как вы можете сказать, они оба вызывают одно и то же представление ( это действие называется «вызвать представление»)это правильное имя?) .
@model IEnumerable<Cumavi.Models.Auction>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th></th>
<th>
IDSubcategory
</th>
<th>
IDCity
</th>
<th>
IDPerson
</th>
<th>
Title
</th>
<th>
TextBody
</th>
<th>
ContactNumber
</th>
<th>
AskingPrice
</th>
<th>
AddressDirection
</th>
<th>
LatestUpdateDate
</th>
<th>
VisitCount
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
<td>
@item.IDSubcategory
</td>
<td>
@item.IDCity
</td>
<td>
@item.IDPerson
</td>
<td>
@item.Title
</td>
<td>
@item.TextBody
</td>
<td>
@item.ContactNumber
</td>
<td>
@String.Format("{0:F}", item.AskingPrice)
</td>
<td>
@item.AddressDirection
</td>
<td>
@String.Format("{0:g}", item.LatestUpdateDate)
</td>
<td>
@item.VisitCount
</td>
</tr>
}
</table>
Они оба наследуются от одной и той же модели.
Мой вопрос: правильно ли я поступаю?Или это просто хак, который мне удалось собрать вместе.Помоги мне, прежде чем я выучу дурную привычку.