• 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

Displaying button click results on same view using model which is based on value entered from view

 
Ranch Hand
Posts: 1282
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create a view from which user can enter value an option from text box and based on the value of option entered by the user, data from the model will be displayed on the view. This works fine if I used 2 views. One for entering the text box option and other for displaying the results. However if I try to to this in the same view, it gives object reference not set error. This is because the model is available only when user enters the text box value and before entering the value itself it will give object reference not set. How can I achieve this using single view?

The code which works fine using 2 views:

Index.cshtml





HelloAction.cshtml







HelloController.cs







Employee.cs


This is the URL using which I run it on local:

http://localhost:57538/Employee/Index



The above code works  but how to achieve the same using a single view instead of 2 views?

Thanks

 
Monica Shiralkar
Ranch Hand
Posts: 1282
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is coming fine now after I have put a null check. Now a new issue has come that is it shows the if statement in the response itself.

This is the code that I have changed:



It shows response as this and shows even the if statement in the response:
if(model!=null) {
1 Richard Thomas
2 Tom Mathews
3 Ronald Walter
}

How can I avoid the if statement to print in the reponse?
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
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!