P
Phil
I am showing a list of items by category. Each item may belong to more than
one category, so the Model features a CategoryList collection for each item.
The CategoryList collection contains a CategoryID (int) and a CategoryName
(string). At the moment, I am iterating the Category collection to find an
item that matches part of the page URL with the CategoryID to write the
category name to the page. It works, but looks and feels horrible. I'm
doing this in the View:
--------------------------------------------------
Items in the
<%
foreach(var item in Model.First().CategoryList)
{
if
(Request.Url.ToString().Substring(Request.Url.ToString().LastIndexOf("/")+1,((Request.Url.ToString().Length-1)-
Request.Url.ToString().LastIndexOf("/"))) != "")
{
if (item.CategoryID ==
Convert.ToInt32(Request.Url.ToString().Substring(Request.Url.ToString().LastIndexOf("/")+1,((Request.Url.ToString().Length-1)-
Request.Url.ToString().LastIndexOf("/")))))
Response.Write(item.CategoryName);
}
} %>
Category
--------------------------------------------------
There must be a better way to do this. Can anyone point me in the right
direction?
Thanks
one category, so the Model features a CategoryList collection for each item.
The CategoryList collection contains a CategoryID (int) and a CategoryName
(string). At the moment, I am iterating the Category collection to find an
item that matches part of the page URL with the CategoryID to write the
category name to the page. It works, but looks and feels horrible. I'm
doing this in the View:
--------------------------------------------------
Items in the
<%
foreach(var item in Model.First().CategoryList)
{
if
(Request.Url.ToString().Substring(Request.Url.ToString().LastIndexOf("/")+1,((Request.Url.ToString().Length-1)-
Request.Url.ToString().LastIndexOf("/"))) != "")
{
if (item.CategoryID ==
Convert.ToInt32(Request.Url.ToString().Substring(Request.Url.ToString().LastIndexOf("/")+1,((Request.Url.ToString().Length-1)-
Request.Url.ToString().LastIndexOf("/")))))
Response.Write(item.CategoryName);
}
} %>
Category
--------------------------------------------------
There must be a better way to do this. Can anyone point me in the right
direction?
Thanks