1

I have no idea why this is happening, I have set the values and debugged it, but it is just not passing the information from the controller to the view. Here is what is going on

Model:

public class QueueFilterModel
{
    public string SelectedFilter { get; set; }
    public string query { get; set; }
    public List<string> MyFilterList { get; set; } 


}

Controller:

[HttpGet]
    public ActionResult Queue()
    {
        QueueFilterModel model = new QueueFilterModel()
        {
            SelectedFilter = "All",
            query = "SELECT * FROM [CHAVI].[dbo].[TicketQueue]",
            MyFilterList = new List<string>()

        };
        model.MyFilterList.Add("All");
        model.MyFilterList.Add("Open");
        model.MyFilterList.Add("Closed");


        return View();
    }

View:

@model RazorARPP.Models.QueueFilterModel
@{
ViewBag.Title = "Queue";
}

<h2>Queue</h2>


    <form action="" method="post" enctype="multipart/form-data" id="MyForm">

        Filter
        <div>
            Filter Options:
        </div>
        <div>
            @Html.DropDownList("test", new SelectList(Model.MyFilterList,Model.SelectedFilter))
        </div>


            <h3>Insert Instructions Here</h3>
                @{
                    var DB = Database.Open("CHAVI");
                    var grid = new WebGrid(DB.Query("SELECT * FROM [TicketQueue]"), null, null, 20);

                    @grid.GetHtml(
                        tableStyle: "webgrid",
                        columns: grid.Columns(
                        grid.Column(header: "Link", style: "labelcolumn", format: (item) => Html.ActionLink("Edit Item", "EditQueue", new { id = item.QueueID})),
                        grid.Column("Description", "Description"),
                        grid.Column("QueueDate", "QueueDate"),
                        grid.Column("Note", "Note"),
                        grid.Column("Status", "Status"),
                        grid.Column("LastUpdated", "LastUpdated")
                            )
                    )
                 }
    </form>

The grid part is working fine (and the query). The problem is in the dropdown, it isn't set to anything there. Any thoughts? Thanks.

1
  • Jason's answer is spot on but I would also like to point out that if you have a SQL statement in your view, you are doing it wrong. Commented Dec 14, 2012 at 15:17

2 Answers 2

1

Are you not passing the model to view?

Should it not be

public ActionResult Queue()
    {
        QueueFilterModel model = new QueueFilterModel()
        {
            SelectedFilter = "All",
            query = "SELECT * FROM [CHAVI].[dbo].[TicketQueue]",
            MyFilterList = new List<string>()

        };
        model.MyFilterList.Add("All");
        model.MyFilterList.Add("Open");
        model.MyFilterList.Add("Closed");


        return View(model);
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Try using:-

public ActionResult Queue()
{
    QueueFilterModel model = new QueueFilterModel()
    {
        SelectedFilter = "All",
        query = "SELECT * FROM [CHAVI].[dbo].[TicketQueue]",
        MyFilterList = new List<string>()

    };
    model.MyFilterList.Add("All");
    model.MyFilterList.Add("Open");
    model.MyFilterList.Add("Closed");


    return View(model);
} 

Comments

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.