J'ai un contrôleur appelé AuctionsController. J'y ai actions appelé Index() et AuctionCategoryListing():Besoin de conseils avant de développer une mauvaise habitude
//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);
}
Comme vous pouvez le dire, ils ont tous deux invoquent le même point de vue (cette action est appelée « d'invoquer une vue » Qu'est-ce que c'est le nom propre. ?).
@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>
Ils héritent tous les deux du même modèle. Ma question est la suivante: est-ce que je fais les choses de la bonne manière? Ou est-ce juste un hack j'ai réussi à gratter ensemble. Aide-moi avant que j'apprenne une mauvaise habitude.
Je jauge des réponses selon upvotes, celui qui est downvoting chaque réponse ici s'il vous plaît arrêter. : \ –
Entendre entendre, ou au moins avoir la courtoisie de donner une raison, nous sommes tous ici pour apprendre au moins contribuer à la discussion en offrant une explication/opinion. – RichardW1001