D
D
Denis Sentyabov2015-03-28 11:51:53
ASP.NET
Denis Sentyabov, 2015-03-28 11:51:53

How to output data to ASP.NET MVC view by replacing ID with values?

There is a database, the main works table has connections by id_po and id_server, the servers and programs tables should be used as a set of reference books for further quick filling.
Project on MVC 4. How to make it as a result to display data so that ID_server and ID_PO are replaced by names and display it in the view?
Was
a8fa3935ee6849099853806416b25994.PNG
Got what I wanted
4ffcb7d41b5244f8a25edcab970ad8f0.PNG
Found a way out Did what I wanted
Controller

public ActionResult Content()
        { 

            ViewBag.item = db.WORKS;
            return View();

        }

View, I did not know that it is possible not to receive data by request, but to substitute what I need in the view itself.
@foreach (MvcAudit2.Models.WORKS item in ViewBag.item)
    {
        <tr>
            <td>
                @item.DATE
            </td>
            <td>
                @item.SERVERS.NAME_SERVER
            </td>
            <td>
                @item.PROGRAMS.NAME_PO
            </td>
            <td>
                @item.VERSION
            </td>
            <td>
                @item.EXECUTOR
            </td>
            <td>
                @item.NomIZM
            </td>
            <td>
                @item.COMMENT
            </td>
            <td>
                @item.STATYS
            </td>

        </tr>

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
saltydogd, 2015-03-28
@saltydogd

Since the View implementation is a strongly typed view , and given "this dictionary requires a model element of type 'System.Collections.Generic.IEnumerable'" you can try
return View(r.ToList());
and match the fields in the View and make it dynamic, without model binding,
and then go through foreach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question