• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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

 
Ranch Hand
Posts: 1282
8
  • Mark post as helpful
  • send pies
  • 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: 1282
8
  • Mark post as helpful
  • send pies
  • 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.
 
Would you like to try a free sample? Today we are featuring tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!