Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 222813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:09:45+00:00 2026-05-11T19:09:45+00:00

I created a stongly typed view in an ASP.Net MVC project I’m working on,

  • 0

I created a stongly typed view in an ASP.Net MVC project I’m working on, the view is just an index page that lists the contents of a SQL table in a grid.

I now want to add the functionality to filter this list. I’ve tried to do this by creating a form in the view with a drop down list containing the values you can filter by. The idea being that when the user submits that form it triggers the controllers Post index method which will grab the selected value the dropdown list from the FormCollection passed into the method.

For example my 2 index methods look like this

 public ActionResult Index()
    {
        DevAdminEntities db = new DevAdminEntities();
        ViewData["StatusDropDown"] = new SelectList(db.TaskStatuses, "TaskStatusId", "StatusName");
        return View(db.Tasks);
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index(FormCollection formValues)
    {
        DevAdminEntities db = new DevAdminEntities();
        ViewData["StatusDropDown"] = new SelectList(db.TaskStatuses, "TaskStatusId", "StatusName");
        return View(from t in db.Tasks where t.Projects.ProjectId == int.Parse(Request.Form["StatusDropDown"]) new { t, t.Projects});
    }

The page displays fine when it loads in its unfiltered form but when I click the submit button to apply a filter I get the following error

“The model item passed into the dictionary is of type ‘System.Data.Objects.ObjectQuery1[System.Int32]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[DevAdmin.Models.Tasks]’.“

The view looks like this

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<DevAdmin.Models.Tasks>>" %>    
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Index</title>
</asp:Content>    
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">    
    <h2>Tasks</h2>        
    <%= Html.ValidationSummary() %>
    <% using (Html.BeginForm()) {%>
        <fieldset>
            <legend>Filters</legend>           
            <p>
               <%= Html.DropDownList("StatusDropDown") %>
                <input type="submit" value="Filter" />
            </p>                    
        </fieldset>
    <% } %>            
    <table>
        <tr>
            <th></th>
            <th>
                TaskId
            </th>
            <th>
                Subject
            </th>
            <th>
                Description
            </th>
        </tr>    
    <% foreach (var item in Model) { %>        
        <tr>
            <td>
                <%= Html.ActionLink("Edit", "Edit", new {  id=item.TaskId }) %> |
                <%= Html.ActionLink("Details", "Details", new { id = item.TaskId })%>
            </td>
            <td>
                <%= Html.Encode(item.TaskId) %>
            </td>
            <td>
                <%= Html.Encode(item.Subject) %>
            </td>
            <td>
                <%= Html.Encode(item.Description) %>
            </td>
        </tr>        
    <% } %>    
    </table>    
    <p>
        <%= Html.ActionLink("Create New", "Create") %>
    </p>    
</asp:Content>

Any idea what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:09:45+00:00Added an answer on May 11, 2026 at 7:09 pm

    Well, it kinda says in the errormessage what you do wrong.

    The view expects a IEnumerable1<Tasks> passed to it as Model, but you’re passing a new { t, t.Projects}

    Also, put some breathing room in your code..

    replace

    return View(*hard to read code here*);
    

    with

    int currentStatus = int.Parse(Request.Form["StatusDropDown"];
    var tasks = db.Tasks.Where(t => t.ProjectId.Equals(currentStatus));
    return View("Index", tasks.AsEnumerable());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Part of my strongly typed Details view created in asp.net mvc: <fieldset > <legend>Fields</legend>
When I'm adding a new strongly-typed view to an ASP.NET MVC project, I can
Keywords: asp.net mvc 3, checkbox list, strongly typed view. So, please don't suggest me
Because I need to build a very strongly-typed & type-safed project for Asp.net MVC.
In ASP.NET MVC one can create strongly typed Views but suppose if a view
I'm just learning ASP.NET MVC and my first project is to create a simple
Ok so I am working with an ASP.NET MVC 3 project. When I first
I'm starting to use DataAnnotations in ASP.NET MVC and strongly typed template helpers. Now
I've a problem with Partial View. I am developing a blog in asp.net mvc
I just started ASP.NET MVC (coming from WebForms) and I'm struggling with some really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.