Answer the question
In order to leave comments, you need to log in
Following links in asp.net mvc?
Hi all. I have a database where there are three columns ID New(the news itself) Title(news title) in the index view I use the database for links and take the title from the Title. The question itself is how to make me click on the link and it will take me to the News view and there is already a selection from the database of this news by name or ID? Or am I doing everything wrong and there are other ways?
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then (the names in the code are approximate):
You must have a controller HomeController
, the controller must have an action (method) Index()
that returns id
all the news you need to the view, links must be generated by asp.net mvc routing tools, something like this @Html.Action("Index", "News", id)
on view, where id
this is the news ID
You must have a controller NewsController
, the controller must have an action(method) Index(int id)
, it takes the news as an argument id
and then id
fetches the news from the database and draws it on the view , the following should be written
in the file :RouteConfig.cs
I advise you to look at the documentation on asp.net mvc or read a book, there is a lot and well written about these basic things
well, these are the very basics + in your question a few questions ... you can do this:
@Html.ActionLink(item.TitleBL , "AphorismDetail", "Record", new { id = item.idBL }, null)
//и так
<a href="@Url.Action("Event", "Events", new { id = item.Event_Id })" title='item.Title'>@item.Title</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question