A
A
Anatoly2016-01-04 23:18:23
ASP.NET
Anatoly, 2016-01-04 23:18:23

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

2 answer(s)
A
Antoxa Zimm, 2016-01-04
@reactive93

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 idall 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 idthis 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 idand then idfetches 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

D
Dmitry Filandor, 2016-01-05
@LifeAct

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>

at the beginning, entering asp mvs is not easy, these video tutorials helped me a lot - ASP.NET MVC 3 video tutorial course

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question