jquery - display different item from a list on click of a button in MVC Mobile -
i have list of customers in customers list.
list<customer> customers= getcustomer("new york");
i want display each customer item in mvc view on click of left , right buttons , save customer @ end.
my mvc view below
| leftbutton | 1 of 5 |rightbutton|
customer: michael
address: 123 park ave, new york
rating: 4
phone: 123456
|buttonsave| |buttonremove|
i hope explained properly, should approach thing done in mvc partial page updates.
here 1 possible solution:
create partial view show single customer record.
model:
public static customer getcustomerinfo(int customerid) { using (var db = new dbcontext()) { return db.customers .where(c => c.customerid == customerid) .firstordefault(); } }
view:
<label><b>customer:</b> @viewbag.customer.name</label><br> <label><b>address:</b> @viewbag.customer.address</label><br> <label><b>rating:</b> @viewbag.customer.rating</label><br> <label><b>phone:</b> @viewbag.customer.phone</label>
controller:
[httpget] [authorize] public actionresult getcustomer(int customerid) { var customer = customermodel.getcustomerinfo(customerid); return partialview(customer); }
on next , previous buttons make ajax call load partial view html appropriate record.
function loadcustomer(customerid) { $.ajax({ url: '/store/getcustomer?customerid=' + customerid, type: "get", datatype: "html", success: function (data) { //fill in div load partial view result $('#customerdiv').html(data); } }); }
on save , delete buttons make ajax call execute desired operation.
this solution appropriate if aspect lots of records in database. if not can cache data on client side , call server on save , delete. solution cache 10 records example , when reach 10th record, cache batch.
Comments
Post a Comment