submitted from value different from what i need to print nextWhat are MVP and MVC and what is the difference?What is the difference between String and string in C#?What is the difference between const and readonly?What is the difference between a field and a property?How to return multiple values from a function?What is the difference between an abstract function and a virtual function?What is the difference between MVC and MVVM?Get int value from enum in C#MVC show Multiple Select List in View from ViewBag?How to return to controller a IEnumerable of the values selected in the view from a list
Risk of getting Chronic Wasting Disease (CWD) in the United States?
How to say job offer in Mandarin/Cantonese?
Theorem, big Paralist and Amsart
What defenses are there against being summoned by the Gate spell?
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
Can divisibility rules for digits be generalized to sum of digits
What do you call a Matrix-like slowdown and camera movement effect?
Which models of the Boeing 737 are still in production?
The use of multiple foreign keys on same column in SQL Server
What is the offset in a seaplane's hull?
What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)
LaTeX closing $ signs makes cursor jump
Is it possible to do 50 km distance without any previous training?
Problem of parity - Can we draw a closed path made up of 20 line segments...
Python: next in for loop
Can I make popcorn with any corn?
Theorems that impeded progress
What are the differences between the usage of 'it' and 'they'?
Arthur Somervell: 1000 Exercises - Meaning of this notation
Languages that we cannot (dis)prove to be Context-Free
Do I have a twin with permutated remainders?
Can I ask the recruiters in my resume to put the reason why I am rejected?
Why don't electron-positron collisions release infinite energy?
What is the word for reserving something for yourself before others do?
submitted from value different from what i need to print next
What are MVP and MVC and what is the difference?What is the difference between String and string in C#?What is the difference between const and readonly?What is the difference between a field and a property?How to return multiple values from a function?What is the difference between an abstract function and a virtual function?What is the difference between MVC and MVVM?Get int value from enum in C#MVC show Multiple Select List in View from ViewBag?How to return to controller a IEnumerable of the values selected in the view from a list
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am making a modification to a large existing project
the existing project is a C# MVC project
It has a complex backend with a clearly well thought out architecture which i have been told not to change.
The Models (which do get passed to the views) are complex and one of the properties on the model is a list of people.
The list of people contains a name and an id
My task is to create a form on the front end which has a load of check boxes which list all of the people in the model.
It also needs to display a list of selected people as tabs (separate from the form)
To generate the check boxes i simply loop through the list of people and use the name as the display text and the id as the input fields value.
IN the back end (since i cant make modifications to the model) I capture the submitted data with a object and assign this objects properties to ViewBag.
Back in the front end the contents of ViewBag are used to print the list of selected people.
The problem is the ViewBag contains the ID's of the people not the Names.
(because the form submits the ID's)
At first I had a loop which prints every item in the ViewBag but this on its own only printed the ID's
To get the Names i have had to put a line in each iteration of the loop which selects a Person from the model where the id is equal to the ViewBag Value
I can then print that persons name rather than their ID
This sort of logic is the sort of thing which should go in the controller, but i cannot put the foreach loop there.
What would be a clean and appropriate way to handle this?
c# model-view-controller model coding-style viewbag
add a comment |
I am making a modification to a large existing project
the existing project is a C# MVC project
It has a complex backend with a clearly well thought out architecture which i have been told not to change.
The Models (which do get passed to the views) are complex and one of the properties on the model is a list of people.
The list of people contains a name and an id
My task is to create a form on the front end which has a load of check boxes which list all of the people in the model.
It also needs to display a list of selected people as tabs (separate from the form)
To generate the check boxes i simply loop through the list of people and use the name as the display text and the id as the input fields value.
IN the back end (since i cant make modifications to the model) I capture the submitted data with a object and assign this objects properties to ViewBag.
Back in the front end the contents of ViewBag are used to print the list of selected people.
The problem is the ViewBag contains the ID's of the people not the Names.
(because the form submits the ID's)
At first I had a loop which prints every item in the ViewBag but this on its own only printed the ID's
To get the Names i have had to put a line in each iteration of the loop which selects a Person from the model where the id is equal to the ViewBag Value
I can then print that persons name rather than their ID
This sort of logic is the sort of thing which should go in the controller, but i cannot put the foreach loop there.
What would be a clean and appropriate way to handle this?
c# model-view-controller model coding-style viewbag
add a comment |
I am making a modification to a large existing project
the existing project is a C# MVC project
It has a complex backend with a clearly well thought out architecture which i have been told not to change.
The Models (which do get passed to the views) are complex and one of the properties on the model is a list of people.
The list of people contains a name and an id
My task is to create a form on the front end which has a load of check boxes which list all of the people in the model.
It also needs to display a list of selected people as tabs (separate from the form)
To generate the check boxes i simply loop through the list of people and use the name as the display text and the id as the input fields value.
IN the back end (since i cant make modifications to the model) I capture the submitted data with a object and assign this objects properties to ViewBag.
Back in the front end the contents of ViewBag are used to print the list of selected people.
The problem is the ViewBag contains the ID's of the people not the Names.
(because the form submits the ID's)
At first I had a loop which prints every item in the ViewBag but this on its own only printed the ID's
To get the Names i have had to put a line in each iteration of the loop which selects a Person from the model where the id is equal to the ViewBag Value
I can then print that persons name rather than their ID
This sort of logic is the sort of thing which should go in the controller, but i cannot put the foreach loop there.
What would be a clean and appropriate way to handle this?
c# model-view-controller model coding-style viewbag
I am making a modification to a large existing project
the existing project is a C# MVC project
It has a complex backend with a clearly well thought out architecture which i have been told not to change.
The Models (which do get passed to the views) are complex and one of the properties on the model is a list of people.
The list of people contains a name and an id
My task is to create a form on the front end which has a load of check boxes which list all of the people in the model.
It also needs to display a list of selected people as tabs (separate from the form)
To generate the check boxes i simply loop through the list of people and use the name as the display text and the id as the input fields value.
IN the back end (since i cant make modifications to the model) I capture the submitted data with a object and assign this objects properties to ViewBag.
Back in the front end the contents of ViewBag are used to print the list of selected people.
The problem is the ViewBag contains the ID's of the people not the Names.
(because the form submits the ID's)
At first I had a loop which prints every item in the ViewBag but this on its own only printed the ID's
To get the Names i have had to put a line in each iteration of the loop which selects a Person from the model where the id is equal to the ViewBag Value
I can then print that persons name rather than their ID
This sort of logic is the sort of thing which should go in the controller, but i cannot put the foreach loop there.
What would be a clean and appropriate way to handle this?
c# model-view-controller model coding-style viewbag
c# model-view-controller model coding-style viewbag
asked Mar 9 at 2:30
megamanmegaman
3231514
3231514
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073445%2fsubmitted-from-value-different-from-what-i-need-to-print-next%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073445%2fsubmitted-from-value-different-from-what-i-need-to-print-next%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown