❔ MVC Enumerate
Hi everyone, I'm currently working on HW4 in CS366 and I am having some trouble figuring out how to pass information using IEnumerable<string> I want it to use the @foreach loop that I have an output hexadecimal values in string form, and also to color divs in the respective colors. Here is images of my code, and also the text in case you want to try running it. I also have a picture of the errors I'm getting, but I'm assuming its because I don't have something to actually iterate through like IEnumerate wants to.
Text file is all my code and errors.
11 Replies
Well, in one action you send no data to the view, in the other you send an object
And yet you claim the model for this view is an
IEnumerable<string>
?Where do you want to be helped, exactly?
https://discord.com/channels/143867839282020352/1078493141759434833
Here is fine. I am new to C# and MVC (started learning it a couple weeks ago in college). I know that I need to return multiple strings in the forms of hexadecimal values. I just need to know how to get those through in such format. My reasoning behind using IEnumerable is I thought I would need to go through a list of strings and output each of them on my view. Obviously it isn't working as intended and thats what I was hoping to get help with.
I mean, sure, if you want to send multiple of X you can use list/array/ienumerable/etc
But the data you pass to the view MUST match what you declare the model for the view is
So I'm passing my model strings and an integer and I want a list of strings back. Where should I declare that?
Well, the
GET
action would return the view with the data you want to pass to it
And the POST
action would receive some other model, and use RedirectToAction()
to redirect to the GET
action
For exampleMy assignment wants me to use the POST action, the reasoning behind the GET action was because when the page first loads it's passed nothing. That's what I was told to do anyways.
Well, then just use a single model
And just use it in the
POST
action
And make it nullable in the view, so it doesn't complain that nothing's there when GET executesWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.