c# - How do you pass an object from the model to the view while specifying which variable of the object? -


so pretty fresh .net, c#, , mvc.

the issue having have created employee object in home controller under index():

public actionresult index(string name, string id, decimal? hourlypayrate, int? hoursworked)     {         var emp = new employee(name, id);          if(name == null || id == null || !hourlypayrate.hasvalue || !hoursworked.hasvalue)         {             return httpnotfound();         }         else         {             return view(emp);         }         } 

i wanting pass view employee's name display title. here current view:

@model practice.models.employee  @{ viewbag.title = ; }  <div class="jumbotron"> <h1>asp.net</h1> <p class="lead">asp.net free web framework building great web sites , web applications using html, css , javascript.</p> <p><a href="http://asp.net" class="btn btn-primary btn-lg">learn more &raquo;</a></p> </div> 

i'm not sure if i'm not calling correct thing @model (still kinda fuzzy on how of works) or if don't understand syntax calling object.

in razor, can write

<p>employee is: @model.name</p> .. 

or in case

viewbag.title = model.name 

the rest looks ok me.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -