ASP.Net MVC Passing multiple parameters to a view

前端 未结 3 1677
广开言路
广开言路 2021-01-04 19:24

In ASP.Net MVC I would like to render a different partial view depending on the renderview query string parameter.

Therefore providing the facility for the user to c

3条回答
  •  旧巷少年郎
    2021-01-04 19:46

    Paul's method is good, but if you decide you want to pass the int, you need to create a view model.

    In your controller add this

    public class ProductsFormViewModel
        {
            // Properties
            public Products Products { get; private set; }
            public int? Renderview { get; private set; }
    
            // Constructor
            public ProductsFormViewModel(Products p_products, int? p_renderView)
            {
                Products = p_products;
                Renderview = renderView;
            }
        }
    

    Then pass this into the view

    return View(new ProductsFormViewModel(products, renderview);
    

    And then in the view

    Inherits="System.Web.Mvc.ViewPage"
    

提交回复
热议问题