submitted from value different from what i need to print next Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!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

Compiling and throwing simple dynamic exceptions at runtime for JVM

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

Putting Ant-Man on house arrest

Network questions

Protagonist's race is hidden - should I reveal it?

Is the Mordenkainen's Sword spell underpowered?

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

2 sample t test for sample sizes - 30,000 and 150,000

Who's this lady in the war room?

Unix AIX passing variable and arguments to expect and spawn

Why aren't these two solutions equivalent? Combinatorics problem

Why did Europeans not widely domesticate foxes?

Why do C and C++ allow the expression (int) + 4*5?

What is the definining line between a helicopter and a drone a person can ride in?

Why do some non-religious people reject artificial consciousness?

Marquee sign letters

Can this water damage be explained by lack of gutters and grading issues?

How to create a command for the "strange m" symbol in latex?

How to mute a string and play another at the same time

What's the difference between using dependency injection with a container and using a service locator?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

"Destructive force" carried by a B-52?

Raising a bilingual kid. When should we introduce the majority language?

Why do people think Winterfell crypts is the safest place for women, children & old people?



submitted from value different from what i need to print next



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!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;








0















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?










share|improve this question




























    0















    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?










    share|improve this question
























      0












      0








      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 9 at 2:30









      megamanmegaman

      3281514




      3281514






















          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
          );



          );













          draft saved

          draft discarded


















          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















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved