• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 2949
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2949
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic