• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How can I avoid the default data to be displayed even before user enters a value in this MVC code?

 
Ranch Hand
Posts: 2962
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a sample .net MVC code for my learning. On running the code it should open a text box from which user can enter option1 or option2. If user selects enter option1 it should display the data from first JSON. If the user enters option2, it should display the data from second JSON. It works. The only problem is that the code displays one of the options by default even before the user enters option1 or option2.


Given below is the code for Hello1Controller.cs where hello action is called from the click of button from view code.





Given below is the code for index.cshtml (the view for Hello1Controller). From here on click of button the user selection goes to the controller method named ActionResult



This code is working fine. The only problem is that the code displays one of the options by default even before user enters option1 or option2. I tried to remove index method to solve this but it did not work. How can I remove this default data displayed even before user enters a value?

I understand that Viewbag should be avoided in this example.I will do that correction once I am done correcting the problem I have listed in this post.

thanks




 
Monica Shiralkar
Ranch Hand
Posts: 2962
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will remove the view bag and replace it with returning model object from the controller. I think this should solve the current problem.
 
This tiny ad is guaranteed to be gluten free.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic