ASP.Net MVC Passing multiple parameters to a view

前端 未结 3 1674
广开言路
广开言路 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 20:09

    Your View Should be something like:

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
    

    Then in MyModel

    Expose Property:

    public bool RenderDetailView {get;set;}
    

    In your controller action:

    public ActionResult Products(string id, int? renderview)
    {
        var products = productRepository.GetProducts(id).ToList();
        return View("Products", new MyModel {RenderDetailView = renderview.HasValue});
    }
    

    Then in your view, make check like:

    <% if (Model.RenderDetailView)
    

    Ideally, all the properties or parameters or data which a View needs in order to present itself should be part of Model.

    I hope it helps.

提交回复
热议问题