I have a controller called AuctionsController. In it, I have actions called Index () and 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); }
As you can tell, they both invoke the same view (this action is called βinvoke view. What is this name?).
@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>
They both inherit from the same Model.
My question is: am I doing everything right? Or is it just a hack that I managed to scrape off. Help me before I find out a bad habit.
asp.net-mvc view controller
delete
source share