samedi 21 avril 2018

ASP Core 2.0 - Calling Controller Functions from a View

I'm a complete beginner with ASP Core and web development in general, so I apologise if this is painfully obvious.

I am looking for a way to call a function that is present in my Controller from my View. This function would be called in reaction to the user clicking a button on their webpage.

Controller Function:

public ActionResult Change(int n)
    {
        ViewData["currentChoice"] = choiceArray[n];
        return View();
    }

View:

@{
    Choice currentPoint = ViewData["currentChoice"] as Choice;
    <h2>@currentPoint.text</h2>
}

//Button - Call Change function in the Controller 

I have previously created a button that links to another page, in this case "Question/Change", but I do not want a redirect. The desired final result would simply update the text on screen by changing the ViewData.

Aucun commentaire:

Enregistrer un commentaire