Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m in Begining lavel in MVC . Now i face problem . i want to use hyper link to retrive data with id and see details another views.How can i solve it.

BrowseViews: <% foreach (var item in Model)
{ %>

<% Html.RenderAction("ViewSingleAdvert", new { id = item.id }); %>

<% } %>

this view indicate ViewSingleAdvert views.
ViewSingleAdvert:
XML
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<WebAdvert.Models.Advert>" %>
<div class="Advert">
    <div id="adverttitle">
         <%: Html.DisplayFor(x=>x.id) %>
    </div>
<div id="adverttitle">
     <%: Html.DisplayFor(x=>x.Title) %>
</div>
<div id="advertexpdate">
     Expires at: <%: Model.ExpirationDate.ToString("d") %>
</div>
<div id="imgDiv">
     <img src='/uploads/<%: System.IO.Path.GetFileName(Model.ImageUrl) %>'  alt="Photo"
            style='visibility: <%: string.IsNullOrEmpty(Model.ImageUrl) ? "hidden" : "visible" %>'  />
</div>
<div id="description">
   <%: Html.DisplayFor(x=> x.Description) %>
</div>
</div>


i want to use hyper link to this view . and its transfer AdvertDetails views .Pls help me . thanks for advance.
Posted

Use This:-

@Html.ActionLink(x=>x.Title, "ViewSingleAdvert", new { id = item.id })
 
Share this answer
 
1.You could add a hyperlink to the entire div like in the next example (razor view equivalent):
@{
//...
string urlDetails = Url.Content(string.Format("~/Advert/AdvertDetails /?id={0}", x.id));
<div class="Advert" onclick="location.href='@urlDetails';" style="cursor: pointer;">
//...
}
</div>


2.And/or you could add the hyperlink to an existing info, like Title:
@{
//...
string urlDetails = Url.Content(string.Format("~/Advert/AdvertDetails /?id={0}", x.id));
<a href="@urlDetails"><span>@x.Title</span></a>
//...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900