C
C#ā€¢2y ago
SkeletonBill

ā” MVC - data is being passed to view, but not displayed

My app worked fine earlier and somehow I broke it, and I do not know how. My model is full of data, and by putting a breakpoint in the razor code I can see that it is being passed to the view as well. However, once the view is rendered, the data is not there. See the total property in the screenshots below. To further confuse things, this is only happening when using lambda expressions. I put a <span>@Model.Total</span> line in just to test, and it is displaying the data in the view. Any ideas? Clearly I broke something but I have no idea what I did.
17 Replies
SkeletonBill
SkeletonBillOPā€¢2y ago
And like a fool I just realized I posted this in the C# discord, but it's VB code... but I mean, it's the same aside from some slight syntax differences, and I don't think there's a large VB discord community that can help. Hope it's OK.
Angius
Angiusā€¢2y ago
What actual HTML does it generate? And yeah, you're right, there won't be many places where you can get help with dead languages
SkeletonBill
SkeletonBillOPā€¢2y ago
<div class="input-group">
<label class="col-8 input-group-text" for="Total">Total</label>
<input class="form-control text-box single-line" id="Total" name="Total" type="text" value="0.00">

<span>10664.52</span>
</div>
<div class="input-group">
<label class="col-8 input-group-text" for="Total">Total</label>
<input class="form-control text-box single-line" id="Total" name="Total" type="text" value="0.00">

<span>10664.52</span>
</div>
here's the html VB might be "dead" but unfortunately it is alive and well in legacy codebases, thankfully it correlates 1-to-1 with C# so you can just write in C# and run it through a translator if you want lol
Angius
Angiusā€¢2y ago
I guess, yeah, it would be 1-to-1 with some ancient version of C#
SkeletonBill
SkeletonBillOPā€¢2y ago
you'd be surprised, it was actively supported until very recently I think
Angius
Angiusā€¢2y ago
IIRC it had a complete feature freeze for years now, just security fixes
Angius
Angiusā€¢2y ago
What if you remove this whole thing?
Angius
Angiusā€¢2y ago
Also, odd that it would use type="text" instead of type="number" for what looks like a float
SkeletonBill
SkeletonBillOPā€¢2y ago
same result, it just messed the css up the equivalent of that line in C# would be Html.EditorFor(model => model.Total, new { htmlAttributes = new { class = "form-control" } }); in case that's unclear
Angius
Angiusā€¢2y ago
Maybe try that htmlAttributes:= thing you have for label? Not sure tbh, everything looks correct to me That said, I don't know much about legacy MVC or about VB, so maybe one of the graybeards in the server will spot an obvious error I can't
SkeletonBill
SkeletonBillOPā€¢2y ago
it's just weird because the breakpoint shows that the data is there, but once the view is rendered, it's MIA šŸ¤·ā€ā™‚ļø I'm happy to blame vb lol Here's a weird behaviour... I manually punched in some value for the total, and it is displaying correctly in both the input and my little test <span> element
SkeletonBill
SkeletonBillOPā€¢2y ago
SkeletonBill
SkeletonBillOPā€¢2y ago
SkeletonBill
SkeletonBillOPā€¢2y ago
and if I call the HttpPost actionresult, it is only updating the <span>, not the input
SkeletonBill
SkeletonBillOPā€¢2y ago
SkeletonBill
SkeletonBillOPā€¢2y ago
I fixed it by rolling back my changes this afternoon, no idea what the problem was.
Accord
Accordā€¢2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server