如何在MVC中使用超级链接来回溯数据 [英] How to Use a hyper Link to Retrive Data in MVC
问题描述
我在MVC的Begining lavel。现在我面临问题。我想使用超链接来检索带有id的数据并查看其他视图的详细信息。我如何解决它。
浏览次数:<%foreach(型号中的var项目)
{%>
<%Html.RenderAction(ViewSingleAdvert,new {id = item.id}); %>
<%}%>
此视图显示ViewSingleAdvert视图。
ViewSingleAdvert:
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:
<%@ 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想要使用超链接到这个视图。和它的转移AdvertDetails视图.Pls帮助我。感谢提前。
i want to use hyper link to this view . and its transfer AdvertDetails views .Pls help me . thanks for advance.
推荐答案
使用此: -
@ Html.ActionLink(x => x.Title,ViewSingleAdvert,new {id = item.id})
Use This:-
@Html.ActionLink(x=>x.Title, "ViewSingleAdvert", new { id = item.id })
1.您可以在整个div中添加超链接,如下一个示例(razor视图等效):
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 /或者您可以将超链接添加到现有信息,例如标题:
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>
//...
}
这篇关于如何在MVC中使用超级链接来回溯数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!