Dynamically load Partial Views

后端 未结 6 1004
醉话见心
醉话见心 2020-12-14 16:58

How can i dynamically load a Partial View?

I mean I have this view, lets say ListProducts, there I select some dropdownlists with products, etc, and wit

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 17:47

    Use jQuery's $.load() with a controller action that returns a partial view.
    For example:

    HTML

    
    
    

    Controller

    public virtual ActionResult Index(string id)
    {
        var myModel = GetSomeData();
        return Partial(myModel);
    }
    

    View

    @model IEnumerable
    
    @if (Model == null || Model.Count() == 0)
    {
        

    No results found

    } else {
      @foreach (YourObjects myobject in Model) {
    • @myObject.Name
    • }
    }

提交回复
热议问题