Call Controller Method Which Return View With Ajax Call From Asp.net View Page

前端 未结 1 1780
名媛妹妹
名媛妹妹 2020-12-11 06:36

I have button. I want to route new view when i clicked the button. The button is like below:

1条回答
  •  無奈伤痛
    2020-12-11 07:24

    If you wants to refresh page:

    Controller:

    public ActionResult Index()
    {            
        return View();
    }
    
    public ViewResult Test()
    {
        ViewBag.Name = Request["txtName"];
        return View();
    }
    

    Index.cshtml:

    @using (Html.BeginForm("Test", "Home", FormMethod.Post ))
    {
         
        
    }
    

    Test.cshtml:

    @ViewBag.Name
    

    =============================================

    If you don't wants to refresh page:

    Controller:

    public ActionResult Index()
    {            
        return View();
    }
    
    [HttpPost]
    public PartialViewResult TestAjax(string Name)
    {
        ViewBag.Name = Name;
        return PartialView();
    }
    

    Index.cshtml:

     
    
    
    
    
    

    TestAjax.cshtml:

    @ViewBag.Name
    

    0 讨论(0)
提交回复
热议问题