• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

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

 
Ranch Foreman
Posts: 2021
12
  • 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 Foreman
Posts: 2021
12
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic