MVC 4 loads a partial view dynamically on one page

I have an MVC 4 application that has one home look. I have three link buttons and you want to dynamically load three different forms based on the click of a button. I am using partial mvc views. So, if I press button-1, it should load partialView-1, and also send value-1 from the corresponding text field to partialView-1.

I am looking for a built-in mvc approach, not working with heavy javascript.

home page to load partial views

+4
source share
2 answers

You can do it like this .

A. Have different methods inside your controller that returnPartialViewResult

[HttpGet]
    public PartialViewResult GetPartialView1(int value)
    {    
        return PartialView("_PartialView1"); //This view should exist in appropriate views folder.
    }

B. @Ajax.ActionLink

@Ajax.ActionLink(
    "Button1",
    "GetPartialView1",
    new { 
        value1 = 1},
    new AjaxOptions
    {
        HttpMethod = "GET",
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "righthandsidebox"
    }
    )

C. UpdateTargetId = "righthandsidebox", div . righthandsidebox PartialView

+2

MVC , , , , . , javascript.

javascript, . , , , . , .

, "", javscript? jQuery, , .

( javascript). , display:none, javascript , . , .

"ajax-" , .

, ... , javascript.

0

Source: https://habr.com/ru/post/1543759/


All Articles