Click here to Skip to main content
       

ASP.NET

 
QuestionChange CSS dynamically using javaScript [modified] Pinmembersonusharma6527-Jan-13 21:36 
AnswerRe: Change CSS dynamically using javaScript PinmvpSandeep Mewara27-Jan-13 23:24 
Questioncapture the signature from signature pad in Web App. Pinmemberpremaa_36@yahoo.co.in27-Jan-13 20:40 
AnswerRe: capture the signature from signature pad in Web App. PinmvpSandeep Mewara27-Jan-13 21:08 
GeneralRe: capture the signature from signature pad in Web App. PinmemberAbhishek Pant27-Jan-13 21:53 
Questionlogin object in asp.net PinmemberLuqman Inam25-Jan-13 0:52 
AnswerRe: login object in asp.net PinmvpSandeep Mewara25-Jan-13 5:03 
AnswerRe: login object in asp.net PinmvpRahul Rajat Singh25-Jan-13 19:17 
QuestionExperience with BootMetro? PinmemberMarco Alessandro Bertschi24-Jan-13 23:06 
AnswerRe: Experience with BootMetro? PinmemberAbhishek Pant25-Jan-13 10:28 
Questionsignature capture from signature pad Pinmemberpremaa_36@yahoo.co.in24-Jan-13 17:36 
AnswerRe: signature capture from signature pad PinmvpSandeep Mewara25-Jan-13 5:03 
AnswerRe: signature capture from signature pad PinmemberAbhishek Pant25-Jan-13 9:51 
QuestionObtaining the SelectedValue of a dropdownlist PinmemberCollin Jasnoch24-Jan-13 2:50 
I am using MVC 4 and I can not get the selected value. I have no idea what I am doing wrong. It seems this should be straight forward but I have pounded my brain on my keyboard for hours now.
 
I have an EntityController and on its construction it builds up a view model for the view. In other words:
 
private AppDBContext _db = new AppDBContext();
private Entities _viewModel = new Entities();
public EntityController()
{
   _viewModel.ActiveEntities = _db.Entities.ToList();
   var platformQry = _db.Platforms.AsEnumerable();
   _viewModel.Platforms = new List<Platform>(platformQry.Distinct());
}
 
Platform is just a simple 2 column item that has an ID and a name. i.e. :
public class Platform
{
    public int ID { get; set; }
 
    [Required]
    public string Name { get; set; }
}
 
The view model is quite simple. It is maintaining the available Platform items, has a value to track the ID of the selected item, and contains a collection of the POCOs (Entity). i.e.:
public class Entities
{
     public IEnumerable<Entity> ActiveEntities { get; set; }
 
     public IEnumerable<Platform> Platforms { get; set; }
 
     public int PlatformFilterId { get; set; }
 
}
 
Now my intention is to use this value (the ID) in a callback to the controller to filter down the ActiveEntities. So here is the Action method (it is just the Index of the controller).
 
public ActionResult Index()
{
    //Build the initial entity query to filter down
    _viewModel.ActiveEntities = _db.Entities.AsEnumerable();
 
    if (_viewModel.PlatformFilterId != 0)
    { 
        //Filter by the platform ID
        _viewModel.ActiveEntities = _viewModel.ActiveEntities.Where(e => e.Platform == _viewModel.PlatformFilterId);
    }
 
    //Ensure the query is run
    _viewModel.ActiveEntities = _viewModel.ActiveEntities.ToList();
    return View(_viewModel);
}
 
Seems simple enough but maybe this is already wrong.... And here is the view:
 
@model AppName.ViewModels.Entities
 
@{
    ViewBag.Title = "Entity Overview";
}
 
<h2>Index</h2>
 
<p>
    @Html.ActionLink("Create New", "Create")
 
    @using (Html.BeginForm("Index", "Entity", FormMethod.Get))
    {
 
        <p>            
            @Html.DropDownListFor(x => x.PlatformFilterId , new SelectList(Model.Platforms, "ID", "Name"), "-- Filter by Platform--")
            <input type="submit" value="Filter" />
        </p>
    }
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ActiveEntities.First().Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ActiveEntities.First().Name)
        </th>
        <th></th>
    </tr>
 
@foreach (var item in Model.ActiveEntities) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CreatedDate)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}
 
</table>
 

The outcome is that I get my dropdown populated correctly, but on the postback (i.e. the Index action method firing after I click "Filter") the PlatformFilterId is always 0 so of course I can never filter. What am I doing wrong?
 
Any help is appreciated.
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

QuestionHow to get the value of a dynamically created textBox in asp.net C#? Pinmembersusanna.floora24-Jan-13 2:46 
AnswerRe: How to get the value of a dynamically created textBox in asp.net C#? Pingroupchester_it2124-Jan-13 14:50 
GeneralRe: How to get the value of a dynamically created textBox in asp.net C#? Pinmembersusanna.floora24-Jan-13 17:54 
GeneralRe: How to get the value of a dynamically created textBox in asp.net C#? Pingroupchester_it2129-Jan-13 4:47 
GeneralRe: How to get the value of a dynamically created textBox in asp.net C#? Pinmembersusanna.floora3-Feb-13 20:30 
GeneralRe: How to get the value of a dynamically created textBox in asp.net C#? Pingroupchester_it216-Feb-13 6:22 
QuestionURL Rewriting PinmemberMaheshPandian24-Jan-13 0:37 
AnswerRe: URL Rewriting PinmemberShameel24-Jan-13 1:00 
GeneralRe: URL Rewriting PinmemberMaheshPandian24-Jan-13 2:28 
QuestionHow to create loocal SMTP server in windows Pinmembersani_alam23-Jan-13 23:59 
AnswerRe: How to create loocal SMTP server in windows PinmvpRichard MacCutchan24-Jan-13 1:54 
QuestionHow to extract data of a table. Pinmemberanubhaw.gupta23-Jan-13 20:06 
Questionhow to use ckeditor in asp.net? PinmemberDaxiii23-Jan-13 0:09 
AnswerRe: how to use ckeditor in asp.net? Pinmembermark merrens23-Jan-13 5:31 
AnswerRe: how to use ckeditor in asp.net? PinmvpSandeep Mewara23-Jan-13 8:20 
Questionhow resize this image before uploading PinmemberJassim Rahma22-Jan-13 8:44 
AnswerRe: how resize this image before uploading Pinmemberjkirkerx22-Jan-13 12:25 
AnswerRe: how resize this image before uploading PinmemberRichard Deeming23-Jan-13 1:53 
QuestionIssue in web farm scenario deployment ASP.NET Pinmembermukeshgaharwar21-Jan-13 19:20 
AnswerRe: Issue in web farm scenario deployment ASP.NET PinmvpSandeep Mewara22-Jan-13 2:41 
QuestionWebResponse Pinmemberpit's_world21-Jan-13 1:50 
AnswerRe: WebResponse PinmemberAli Al Omairi(Abu AlHassan)21-Jan-13 4:05 
Questioncolumn 'member_channel_name' does not belong to table PinmemberJassim Rahma20-Jan-13 9:57 
AnswerRe: column 'member_channel_name' does not belong to table PinmentorBrij20-Jan-13 21:52 
JokeRe: column 'member_channel_name' does not belong to table Pinmemberjkirkerx22-Jan-13 12:32 
QuestionPost and Get process ASP.NET MVC PinmemberPatrik von Frieling20-Jan-13 5:10 
AnswerRe: Post and Get process ASP.NET MVC Pinmemberdeflinek21-Jan-13 3:23 
QuestionResource files show empty content PinmemberAli Al Omairi(Abu AlHassan)19-Jan-13 23:19 
AnswerRe: Resource files show empty content PinmvpSandeep Mewara20-Jan-13 1:18 
GeneralRe: Resource files show empty content PinmemberAli Al Omairi(Abu AlHassan)20-Jan-13 1:51 
GeneralRe: Resource files show empty content PinmvpSandeep Mewara20-Jan-13 3:01 
QuestionViewState not working in UserControl PinmemberJassim Rahma19-Jan-13 5:29 
AnswerRe: ViewState not working in UserControl [modified] Pinmemberjkirkerx19-Jan-13 18:35 
AnswerRe: ViewState not working in UserControl PinmemberRichard Deeming21-Jan-13 2:07 
QuestionHow can we export data into csv format in c#.net PinmemberEr Atul Sharma18-Jan-13 23:31 
AnswerRe: How can we export data into csv format in c#.net PinmvpSandeep Mewara19-Jan-13 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140902.1 | Last Updated 2 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid