Kingkong Kingkong - 2 months ago 16
C# Question

Change view content without refreshing page or creating a new view

I'm working on a multiplayer quiz, and I'm currently in a situation where i have to change the contents of my quiz view where I have 1 question and 4 answers, but everytime the user clicks on an answer (which is a button), I need to populate the buttons (answers) and the question with new values.

What would be a simple way of achieving this page refresh without actually having to carry an ID as parameter in my url everytime?


e.g. you can use ajax


public class CustomerController : Controller 
   public ActionResult Index() 
       return View();

   public ActionResult GetUpdate()
      return Json(new { success = true, newPar = 4 }, JsonRequestBehavior.AllowGet);


        url: '@Url.Action("GetUpdate")',
        dataType: "json", 
        type: "POST", 
        contentType: 'application/json; charset=utf-8', 
        cache: false, 
        data: {}, //pass argument if needed
        success: function (data) {
            if (data.success) { 
        error: function (xhr) {

another option is to use SignalR:

the libary does all for you and you can call methods from serverside