Select particular view for view - ASP. NET MVC

Asked

Viewed 252 times

-1

I am learning the ASP.NET MVC and I came across a situation that would like your help.

I have a view that shows the result of a database query on the screen. Each record shown has an identification (ID), and I need to click change to hit something that is in what is being presented, until then it’s okay.

However, for example, the first record shown is to change the records in table "A", the second record to change the data in table "C", the third in table "D" and so on. The problem is just this, there is a way to click the Edit button, it point to which view corresponds the error and open this view, ie, program if the view has error type 1 opens the view "A", if error type 2 opens the view "B" and so on.

  • What have you tried to do? Are you making a mistake? Updates the question to make it easier to answer.

  • This behavior you can define in Controller. For example, if the edit button runs a method and sends the x ID, it does y.

  • It is interesting to make available the code you described there!

  • Yes, there is a way.

1 answer

0

You can do it using Razor @HTML.Linkaction in the View and create Action in the controller.

@Html.ActionLink("titulo do link", "QualActionQuer", "DeQualcontrollerQuer", new { id = "123" }, null)

Ex:

View

@Html.ActionLink("titulo do link A", "ActionTabelaA", "AlteraTabelaController", new { id = 1 }, null)
@Html.ActionLink("titulo do link B", "ActionTabelaB", "AlteraTabelaController", new { id = 2 }, null)
@Html.ActionLink("titulo do link C", "ActionTabelaC", "AlteraTabelaController", new { id = 3 }, null)
@Html.ActionLink("titulo do link D", "ActionTabelaD", "AlteraTabelaController", new { id = 4 }, null)

Controller

public class AlteraTabelaController : Controller
{
    public ActionResult ActionTabelaA()
    {
        return View();
    }

    public ActionResult ActionTabelaB()
    {
        return View();
    }

    public ActionResult ActionTabelaC()
    {
        return View();
    }

    public ActionResult ActionTabelaD()
    {
        return View();
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.