asp.net mvc - using a view for multiple controller Actions, return to initial view -
i have view displays list of items, i'm planning on using actions view (the view same, different data displayed)
i'm using dialog addedit (this works fine) using same dialog throughout.
my query best demonstrated in below example...
equipment view
actionresult pcs()... actionresult laptops()...
so under pcs controller hit edit , modify data, when update data, im returned back... want returned action started with
so if edit pc, on update, dialog returns me pcs, if edit laptop go laptops.
i thinking need pass variable through addeditview show wich controller refereed me.
does above make sense, can offer best way achieve this?
thanks
edit: adding current code
i cant think how @ moment, thought id set mode under users, , retrieve mode, in addedit get, not sure how send mode add edit get
can in below somewhere? thanks
@html.actionlink("edit", "addeditrecord", new { id = item.id }, new { @class = "editdialog" }) controller // get: /users
public actionresult users() { viewbag.title = "user equipment"; viewbag.mode = "users"; string[] arritems = new string[] { "laptop", "workstation", "mobile","monitor","other peripheral","home printer","home router","removable device" }; var tblequipments = d in db.tblequipments.include(t => t.user).include(t => t.changelog).asenumerable() (arritems.contains(d.assettype)) && (d.deleted != 1 || d.deleted == null) && (d.stock != 1 || d.stock == null) && (d.decommissiondate == convert.todatetime("1900-01-01") || d.decommissiondate == convert.todatetime("0001-01-01") || d.decommissiondate == null) select d; return view("equipment",tblequipments.tolist()); } //get: /addedit [httpget] public actionresult addeditrecord(int? id,string mode) { viewbag.mode = mode; if (request.isajaxrequest()) { if (id != null) { viewbag.isupdate = true; tblequipment equipment = db.tblequipments.where(m => m.id == id).firstordefault(); return partialview("_addedit", equipment); } viewbag.isupdate = false; return partialview("_addedit"); } else { if (id != null) { viewbag.isupdate = true; tblequipment equipment = db.tblequipments.where(m => m.id == id).firstordefault(); return partialview("addedit", equipment); } viewbag.isupdate = false; return partialview("addedit"); } } [httppost] public actionresult addeditrecord(tblequipment equipment, string cmd) { if (modelstate.isvalid) { switch (cmd) { case "add": try { db.tblequipments.add(equipment); db.savechanges(); return redirecttoaction("index"); } catch { } break; case "update": try { tblequipment item = db.tblequipments.where(m => m.id == equipment.id).firstordefault(); if (item != null) { item.assetno = equipment.assetno; item.machinename = equipment.machinename; db.savechanges(); } return redirecttoaction("index"); } catch { } break; } } if (request.isajaxrequest()) { return partialview("_addedit", equipment); } else { return view("addedit", equipment); } } add edit modal view @using (ajax.beginform("addeditrecord", "equipment", new ajaxoptions { httpmethod = "post",onsuccess = "onsuccess()", loadingelementid = "dvloading" })) { @html.validationsummary(true) <div id="equipmentdialog"> <fieldset> <legend>product</legend> @if (viewbag.isupdate == true) { @html.hiddenfor(model => model.id) } <div class="editor-label"> @html.labelfor(model => model.machinename) </div> <div class="editor-field"> @html.editorfor(model => model.machinename) @html.validationmessagefor(model => model.machinename)
sorted!
1.i added viewbag action 2.used viewbag in querystring edit 3.put querystring in hiddenfield 4.got fieldvalue on form post , redirect action of field value
thanks help
Comments
Post a Comment