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

  • Home
  • SEARCH
  • 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 8522299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:04:46+00:00 2026-06-11T07:04:46+00:00

I have an Index view in an MVC3 application with a @model which is

  • 0

I have an Index view in an MVC3 application with a @model which is ienumerable. In this model I have an accountID which I want to use to populate my dropdownlist in the view filter with the accounts so that the user will be able to filter for accounts.

Which is the best way to achieve this?

Thanks in advance.

This is the view:

@model IEnumerable<MoneyAdmin.Model.ContaAReceber>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Partial("_SubmenuAdmin")

<div class="tituloCadastro">
    Lista de Contas a Receber
</div>

<div class="buttonContainer novo">
    @Html.ActionLink("Nova Conta", "Create")
</div>

<div class="filtros">
    @using (Html.BeginForm()) { 
        <div class="filterField">
            <label>Data Inicial:</label>
            @Html.TextBox("dataInicial", @DateTime.Now.ToShortDateString())
        </div>
        <div class="filterField">
            <label>Data Final:</label>
            @Html.TextBox("dataFinal", @DateTime.Now.ToShortDateString())
        </div>
        <div class="filterField">
            <label>Tipo de Conta:</label>
            @Html.DropDownList("contaID")
        </div>

        <input type="submit" value="Atualizar" />
    }     
</div>

And the controller method:

public ViewResult Index(string dataInicial, string dataFinal, string contaID)
    {
        var crs = from cr in db.contasareceber.Include("contas")
                       select cr;

        if (!string.IsNullOrEmpty(dataInicial) && !string.IsNullOrEmpty(dataFinal))
        {
            DateTime di = DateTime.Parse(dataInicial);
            DateTime df = DateTime.Parse(dataFinal);

            crs = crs.Where(cr => cr.dataPagamento >= di && cr.dataPagamento <= df);
        }

        return View(crs.ToList());
    }
  • 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-06-11T07:04:48+00:00Added an answer on June 11, 2026 at 7:04 am

    Thanks for everyone!

    I found the answer as like this.

    Populate the viewbag in the controller like that:

    ViewBag.Contas = new SelectList(db.contas, "contaID", "nome");
    

    Then use it in the dropdownlist like that:

    @Html.DropDownList("Contas");
    

    Simple and it works!

    Thanks for everyone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an index view that I want to update automatically as the user
I have the following code in my index view. latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10] for entry
I have folders and pages /admin/add/index.php, /admin/edit/index.php & /admin/view/index.php which all are requiring page
I have a view and template called index.html. I have a image which is
I have the following view: @model MyModel1 @{ ViewBag.Title = Index; Layout = ~/Views/Shared/_Layout.cshtml;
My application is in Asp.Net MVC3 coded in C#.Net. I have Views which contains
I have a MVC3 application, based on default layout from VS 2010, which I
I have an MVC3 web application where controllers use services to perform certain tasks.
I have this simple MVC 3 application which simply has two controllers(Home and Edit),
I have a simple MVC3 application that I want to retrieve some configuration details

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.