c# - Dynamically create webpages with different URLs -
wasn't able find this.. maybe wasn't looking correctly. pretty view:
<div class="jumbotron"> @foreach (datarow dr in ds.tables[0].rows) { <ul> <li>@dr["name"].tostring() - @dr["distance"].tostring()</li> </ul> } </div>
i want create new page (using c# , mvc) each of bullet points different url's depending on name. how can that? use actionlink? have routing?
basically let's have list of restaurants, want when click on restaurant takes different url yourdomain.com/restaurant-name
, , want populate page html. how go doing that?
the default route takes urls in format: domain.com/controller/action/id
so if code controller called restaurantscontroller
action view
can pass id of restaurant want view... thusly:
yes, vb, i'm sure can translate
public function view(optional byval id string) actionresult ' fetch restaurant data... dim model restaurant = restaurantrepository.getrestaurantbyid(id) return view(model) end function
access action via: domain.com/restaurants/view/whatever-your-restaurant-id-is
then make links in razor view can do:
@html.actionlink("link text here", "view", "restaurants", htmlattributes:=nothing, routevalues:= new {.id = dr["name"]})
Comments
Post a Comment