I am not good at writing blogs... the content should be as simple as possible... just for example ..
In asp.net MVC, only one Model can be returned by default at a time. If multiple datasets are called, ViewData can only be used for export. This seems troublesome, you can implement the model extension method... I am only an entry-level learner. I may not understand or describe it clearly. If there is a better method or suggestion.
First, define a class in the controller. The content is as follows:
Public class lviewModel
{
Public List <Sorts> sortList {get; private set ;}
Public List <Articles> artList {get; private set ;}
Public lviewModel (List <Models. Sorts> sortlists, List <Models. Articles> artlists)
{
This. sortList = sortlists;
This. artList = artlists;
}
}
To receive two lists and then return
Models. ESCMSContext escms = new ESCMS_MVC_ SQL .Models.ESCMSContext ();
Return View (new lviewModel (escms. sortList (), escms. artList ()));
When using
The first line of the View File to be referenced
<% @ Page Title = "" Language = "C #" MasterPageFile = "~ /Views/Shared/Site. Master "Inherits =" System. Web. Mvc. ViewPage <ESCMS_MVC_ SQL .Controllers.lviewModel> "%>
Change ESCMS_MVC_ SQL to the name of your project.
Then you can
Model. artList
Model. sortList
This is used.
<Asp: Content ID = "Content2" ContentPlaceHolderID = "MainContent" runat = "server">
<Form id = "form1" runat = "server">
<H2> list
<Table>
<Tr>
<Th> </th>
<Th>
ArtID
</Th>
<Th>
ArtTitle
</Th>
<Th>
ArtSort
</Th>
<Th>
ArtSort
</Th>
</Tr>
<% Foreach (var item in Model. artList)
{%>
<Tr>
<Td>
<% = Html. ActionLink ("Edit", "Edit", new {id = item. ArtID}) %> |
<% = Html. ActionLink ("Details", "Details", new {id = item. ArtID}) %>
</Td>
<Td>
<% = Html. Encode (item. ArtID) %>
</Td>
<Td>
<% = Html. Encode (item. ArtTitle) %>
</Td>
<Td>
<% = Html. Encode (item. ArtSort) %>
</Td>
<Td>
<% = Html. Encode (item. Sorts. SortName) %>
</Td>
</Tr>
<% }%>
</Table>
<Table>
<Tr>
<Th> aa </th>
<Th> bb </th>
</Tr>
<% Foreach (var item in Model. sortList)
{%>
<Tr>
<Td>
<% = Html. ActionLink ("Edit", "Edit", new {/** // * id = item. PrimaryKey */}) %> |
<% = Html. ActionLink ("Details", "Details", new {/** // * id = item. PrimaryKey */}) %>
</Td>
<Td>
<% = Html. Encode (item. SortName) %>
</Td>
</Tr>
<% }%>
</Table>
</Form>
</Asp: Content>
In this way, it's quite simple. It's just a bit complicated. I think Microsoft should provide such a class by default, which is easy to write ..