c# - ASP.Net MVC 4 Display Single Row of Data using button -
i working on asp.net mvc 4 application , trying display single row of data data base instead of rows.
the website designing has list of buttons , when each button clicked data corresponding row in database displayed e.g. button1 - row1, button2 - row2 etc...
currently displayed on http://myexample/movies/onemovie
displayed on http://myexample/movies/
the code have in controller this:
public actionresult onemovie(int id = 0) { movie movie = db.movies.single(m => m.id == id); if (movie == null) { return httpnotfound(); } return view(movie); }
the button code is:
<input id="button1" type="button" value="button" name="id"/> <input id="button2" type="button" value="button" name="id"/>
can me display data corresponding row when button clicked?
ok when generate buttons loop collection id's of movies, here button need :
<input type="button" value="go somewhere else" onclick="location.href='@url.action("onemovie", "controllername", new { id=1 } )'" />
set view id= model.movieid
this allow make request @ action:
public actionresult onemovie(int id) { return view(); }
edit ajax solution
in index page:
function getmoviebyid(movieid) { var url = "/home/onemovie"; $.getjson(url, { id: "movieid"}, function (data) { /* put movie div here */ }); }
your button like:
<input type="button" value="go somewhere else" onclick=getmoviebyid(1) />
and action:
public jsonresult onemovie(int id) { ... var items = db.movies.where... return json(items , jsonrequestbehavior.allowget); }
Comments
Post a Comment