Click here to Skip to main content
15,885,914 members

Comments by AnalogNerd (Top 11 by date)

AnalogNerd 4-Feb-15 13:46pm View    
You're absolutely correct, I missed that. Good catch.

ExecuteScalar would have to be run first into an object, and then you could check that object for DbNull.Value. If it isn't null, conver to an integer.

Basically, Pete's answer above is what I was going for (but didn't quite make it).
AnalogNerd 31-Mar-14 9:29am View    
What version of unity are you using?
AnalogNerd 6-Jun-13 14:07pm View    
My problem with a foreach is that it was not returning my model to the action when I posted. This may have been because my model for the view was a typed List. I created a new viewmodel that has a list in it of my queues. I then did a foreach, same thing.

I then did a EditorTemplate, here's the new code in my view:
@Html.EditorFor(m => m.Changes)

and in the template:
@Html.HiddenFor(m => Model.Id)
@Model.Id

And the result:
<input id="Changes_0__Id" name="Changes[0].Id" type="hidden" value="7617" />
7618
AnalogNerd 6-Jun-13 13:32pm View    
I changed it to a foreach, and while this might not be the correct way to do this, the result was interesting.

@foreach(var item in Model)
{
counter++;
@Html.Hidden("[" + counter + "].Id", item.Id)
<li>@item.Id</li>
}

Result:
<input name="[1].Id" type="hidden" value="7616" /> <li>7617</li>

Code:
@foreach(var item in Model)
{
counter++;
@Html.HiddenFor(m => item.Id)
<li>@item.Id</li>
}

Result:
<input id="item_Id" name="item.Id" type="hidden" value="7617" /> <li>7617</li

AnalogNerd 6-Jun-13 13:00pm View    
My getter doesn't do anything:

public int Id { get; set; }