asp.net mvc - MVC4 render item that uses variable? -


I'm new to MVC, I have in my view:

  @ { MyObjectType myNameObject = getMyNameObject (); } & Lt; P & gt; Name: @ myNameObject.firstName & lt; / P & gt;   

Desing is trying to implement when the line comes from "name: @ myNameObject.firstName" module or ViewBag and still raises the value of @myNameObject.firstName Is it possible? Thank you

Your controller action method should get the data and pass it in the view. Using a view model is usually a way to go, but for a one-off data, the workspace also works like this:

  // View the model public class MyViewModel {public string name {Get; Set;}} // Controller Mode Public Function MyPage () {MyViewModel Model = serviceLayer.GetMyData (); See Return (Model); } // MyPage View @modelmiviammed & lt; P & gt; Name: @model Name & lt; / P & gt;    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -