i create class poi , class address.
public class poi { public string id { get; set; } public string title { get; set; } public datetime created { get; set; } public datetime modified { get; set; } public address address { get; set; } // ... } public class address { public string street { get; set; } public string zip { get; set; } public string city { get; set; } public string country { get; set; } } how possible generate view poi/details.cshtml including fields of address?
you have pass address down model view.
in controller:
public actionresult details() { var model = new address(); model.street = "test address"; return view(model); } then in view, add following:
@model address which allow view know dealing typed address model.
you can use @html.displayfor list of properties within view, example:
@html.displayfor(m => m.street) @html.displayfor(m => m.zip) @html.displayfor(m => m.city) @html.displayfor(m => m.country) however, best create viewmodel rather using address poco directly. viewmodel may information different layer, example database or web service, invoke layer independently rather in controller, allows better separation of concerns.
Comments
Post a Comment