In my Index view I have the usual Edit, Details and Delete links. I've made icons for them, and since I use them everywhere I placed them in a Partial View.
Now, I do not have the feeling I'm doing it best practice here. So my question is: How to optimize it, or what should be different for best practice.
The Partial View:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MVC2_NASTEST.Models.ButtonDetail>" %>
<%if (Model.edit) { %>
<a href='<%= Url.Action("Edit", Model.RouteValues) %>'>
<img src="<%= Url.Content("~/img/pencil.png") %>" alt="Edit" width="16" /></a>
<%} if (Model.details) { %>
<a href='<%= Url.Action("Details",Model.RouteValues) %>'>
<img src="<%= Url.Content("~/img/application_view_detail.png") %>" alt="Details" width="16" /></a>
<%} if (Model.delete) { %>
<a class="delbtn" href='<%= Url.Action("Delete",Model.RouteValues) %>'>
<img src="<%= Url.Content("~/img/cancel.png") %>" alt="Delete" width="16" /></a>
<%} %>
The ViewModel:
using System;
namespace MVC2_NASTEST.Models {
public partial class ButtonDetail {
public object RouteValues { get; set; }
public bool edit { get; set; }
public bool details { get; set; }
public bool delete { get; set; }
}
}
can or should viewmodels be in the Models namespace? or place them in a different namespace? what is best practice here?
The Index View:
<% foreach (var item in Model) { %>
<tr>
<td>
<% Html.RenderPartial("buttons", new MVC2_NASTEST.Models.ButtonDetail() { RouteValues = new { id = item.hlpb_ID, test = item.hlpb_Ontvanger }, edit = true, details = true, delete = true }); %>
</td>
<td>
<%: item.hlpb_Titel %>
</td>
<td>
<%: item.hlpb_Schooljaar %>
</td>
<td>
...
</td>
</tr>
<% } %>
Especially the part in the Index view doesn't look best practice in my eyes.