1

This is my controller that return list of my objects:

public ActionResult ShowList(string site)
{
    var list = db.Objects.Where(x => x.protocol == site).ToArray();
    ViewBag.Files = list;
    return View();
}

Index.cshtml:

@model IQueryable<AutomationCapturesMVC.Models.Capture>
@{
    ViewBag.Title = "ShowList";
}

    <table>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.fileName</td>
                <td>@item.browser</td>
            </tr>
        }
    </table>

Currently get an NullReferenceException I have checked and the return list ins't empty

1

1 Answer 1

4

You have to return your list in param of View() method :

public ActionResult ShowList(string site)
{
    var list = db.Objects.Where(x => x.protocol == site).ToList();
    return View(list);
}

Hope it helps

Sign up to request clarification or add additional context in comments.

3 Comments

foreach statement cannot operate on variables of type public definition for 'getenumerator' what i am ding wrong ?
Change in your view the declaration of the model from IQueryable to List<AutomationCapturesMVC.Models.Capture>.
BTW, how can i order this object with all its properties in listview maybe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.