留在选择行后提交(保存) [英] Stay on selected row after submit(save)
问题描述
我使用asp.net mvc4。我有一个网格,您可以选择一个行,然后你可以编辑的项目。比如你是第3页上,并要在该网页上编辑一行。所以,你选择该行。但是再经过你有救你将返回到第3页的行,但该行不再被选中。我有这样的:
这是索引页,在这里你可以选择一行。在这里你可以选择要与选定行做什么。
< TD类=隐藏>
<跨度>
@if(String.IsNullOrEmpty(item.UrlName)及!&安培;!String.IsNullOrEmpty(item.FormName)){
@ Html.RouteLink(Resources.Action.Navigation。preVIEW,产品preVIEW,新的{PRODUCTURL = item.UrlName,customerSchema = custSchema},{新目标=_blank})
}
其他{
@(Resources.Action.Navigation。preVIEW)
}
| @ Html.ActionLink(Resources.Action.Navigation.Details,详细信息,新{ID = item.Id})
| @ Html.ActionLink(Resources.Action.Navigation.Edit,编辑,新{ID = item.Id})
< / SPAN>
< / TD>
这是编辑页面:
与两个按钮:
< DIV CLASS =行>
< DIV CLASS =COL-XS-12>
@ Html.RenderNotifications()
< / DIV> < DIV CLASS =COL-XS-12填充底-10>
<按钮式=提交值=保存级=BTN BTN-成功>< I类=发FA-FW FA-检查>< / I> @ Resources.Action.Navigation.Save< /按钮> < A HREF =@ Resources.Action.Navigation.JSBack级=BTN BTN-危险>< I类=发FA-FW FA-次>< / I> @ Resources.Action .Navigation.Cancel< / A>
< / DIV>
< / DIV>
感谢您
我用这作为表:
<表类=table表条纹表边框的表格,悬停的dataTable SFS可选择SFS-COL1右对齐>
这是我的javascript:
$(文件)。就绪(函数(){
无功表= $('表响应')数据表()。 $('#表响应TBODY')。在('点击','TR',函数(){
如果($(本).hasClass('选择')){
$(本).removeClass('选择');
}
其他{
表$('tr.selected')removeClass移除('选择')。;
$(本).addClass('选择');
}
});
});
这是我的编辑方式:
公众的ActionResult编辑(INT?ID)
{ VAR页=会话[页];
会话[页] =页; 如果(ID == NULL)
{
返回新的HTTPStatus codeResult(的HTTPStatus code.BadRequest);
}
产品产品= db.Products.Find(ID);
如果(产品== NULL)
{
抛出新的HttpException((INT)的HTTPStatus code.NotFound,NULL);
} SetCreateEditProductLists(产品,customerSchema); EditProductModel editModel =新EditProductModel();
editModel.Product =产品;
editModel.Db = DB; DeserializeAuthenticationSettings(editModel);
DeserializePaymentSettings(editModel);
DeserializeConnectors(editModel);
反序列化prefillMappings(editModel);
ViewBag.Model = editModel;
返回查看(editModel);
}
这是我的帖子编辑:
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(假)]
公众的ActionResult编辑(EditProductModel进入)
{
entry.Product.ModificationDate = DateTime.UtcNow;
// VAR页= TempData的[页];
// TempData的[页] =页;
//ViewBag.CurrentPage = 2;
如果(ModelState.IsValid)
{
db.Entry(entry.Product).STATE = EntityState.Modified; db.Entry(entry.Product).Property(型号=> model.Guid).IsModified = FALSE;
db.Entry(entry.Product).Property(型号=> model.CreationDate).IsModified = FALSE;
db.Entry(entry.Product).Property(型号=> model.IsProduction).IsModified = FALSE; entry.Product.IsProduction = StateHelper.IsTestMode()?假:真实的; HandleProductSelections(entry.Product);
SerializeAuthenticationSettings(输入);
SerializePaymentSettings(输入);
SerializeConnectors(输入);
序列化prefillMappings(输入); 如果(SaveDbChanges()){
//记录一个更新的产品的审核跟踪事件。
{
ATEvent atEvent = AuditTrailHelper.NewEvent(ATEventType.ProductUpdated,HttpContext的,db.Schema,entry.Product);
atEvent.StringArg = entry.Product.Name;
ATEventLogger.Current.LogEvent(atEvent);
}
AddDelayedNotification(Resources.Entity.Environment.ItemSavedMessage,Notification.NotificationType.Success); //返回RedirectToAction(指数,新的{页=页});
// VAR页= TempData的[页];
// TempData的[页] =页;
VAR页=会话[页];
会话[页] =页; VAR ID =会话[ID];
会话[ID] = ID;
返回RedirectToAction(指数,新的{页,ID = entry.Product.Id});
}
}
AddDelayedNotification(Resources.Entity.Environment.ItemNotSavedError,Notification.NotificationType.Error);
返回编辑(entry.Product.Id);
}
这是Index视图:
< DIV CLASS =表响应ID =榜样>
<表类=table表条纹表边框的表格,悬停的dataTable SFS可选择SFS-COL1右对齐ID =榜样>
<&THEAD GT;
&所述; TR>
<第i个
@ Html.RouteLink(Html.DisplayNameFor(型号=> firstItem.Id)的ToString(),分类产品,新{sortColumn =ID,中将sortOrder =(ViewBag.sortColumn ==ID及放大器;&放!?; ViewBag.sortOrder =降序)说明:,搜索字符串= ViewBag.SearchString,过滤器= ViewBag.Filter})
@ ViewHelper.GetSortIndicator(ID,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
<第i个
@ Html.RouteLink(Html.DisplayNameFor(型号=> firstItem.Name)的ToString(),分类产品,新{sortColumn =名,中将sortOrder =(ViewBag.sortColumn ==名和放大器;&放!?; ViewBag.sortOrder =降序)说明:,搜索字符串= ViewBag.SearchString,过滤器= ViewBag.Filter})
@ ViewHelper.GetSortIndicator(名,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
<第i个
@ Html.RouteLink(Html.DisplayNameFor(型号=> firstItem.IsEnabled)的ToString(),分类产品,新sortColumn =已启用,=(ViewBag.sortColumn ==已启用{中将sortOrder&放大器;&放!?; ViewBag.sortOrder =降序)说明:,搜索字符串= ViewBag.SearchString,过滤器= ViewBag.Filter})
@ ViewHelper.GetSortIndicator(已启用,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
<第i个
@ Html.RouteLink(Html.DisplayNameFor(型号=> firstItem.FormName)的ToString(),分类产品,新{sortColumn =表格名称中将sortOrder =(ViewBag.sortColumn ==表格名称&放大器;&放!?; ViewBag.sortOrder =降序)说明:,搜索字符串= ViewBag.SearchString,过滤器= ViewBag.Filter})
@ ViewHelper.GetSortIndicator(表格名称,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
<第i个
@ Html.RouteLink(Html.DisplayNameFor(型号=> firstItem.TemplateName)的ToString(),分类产品,新{sortColumn =设计中将sortOrder =(ViewBag.sortColumn ==设计&放大器;&放!?; ViewBag.sortOrder =降序)说明:,搜索字符串= ViewBag.SearchString,过滤器= ViewBag.Filter})
@ ViewHelper.GetSortIndicator(设计,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
<第i个
@ Html.RouteLink(Resources.Entity.Product.PublicUrl,分类产品,新{sortColumn =URLNAME中将sortOrder =(ViewBag.sortColumn ==URLNAME&放大器;&安培;!ViewBag.sortOrder =降序 ?)说明:,搜索字符串= ViewBag.SearchString,过滤器= ViewBag.Filter})
@ ViewHelper.GetSortIndicator(URLNAME,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
<第i个
@ Html.DisplayNameFor(型号=> firstItem.SubmittedForms)
< /第i
<第i个
@ Html.RouteLink(Html.DisplayNameFor(型号=> firstItem.ModificationDate)的ToString(),分类产品,新{sortColumn =修改,中将sortOrder =(ViewBag.sortColumn ==修改&放大器;&放!?; ViewBag.sortOrder =降序)说明:,搜索字符串= ViewBag.SearchString})
@ ViewHelper.GetSortIndicator(改良,ViewBag.sortColumn,ViewBag.sortOrder)
< /第i
百分位类=隐藏>< /第i
< / TR>
< / THEAD>
<&TBODY GT;
@foreach(以型号VAR项)
{
&所述; TR>
&所述; TD>
@ Html.DisplayFor(modelItem => item.Id)
< / TD>
&所述; TD>
@ Html.DisplayFor(modelItem => item.Name)
< / TD>
&所述; TD>
@ Html.DisplayFor(modelItem => item.IsEnabled)
< / TD>
&所述; TD>
@ {
布尔VIEWLINK = item.IsEnabled;
如果(!String.IsNullOrEmpty(item.FormName))
{
VAR形式= item.FormLibraryEntry;
如果(格式== NULL){
VIEWLINK = FALSE;
@ Html.DisplayFor(modelItem => item.FormName)
<环境监察及GT;(@ Resources.Entity.Environment.Removed)LT; / EM>
}
其他
{
@ Html.DisplayFor(modelItem => form.Name)
< A HREF =@ Url.Action(详细信息,FormLibrary,新{ID = item.FormName})>< I类=发FA-FW FA-外部链接文本的方信息>&下; / I GT;&下; / A>
}
}
}
< / TD>
&所述; TD>
@ {
如果(!String.IsNullOrEmpty(item.TemplateName))
{
VAR模板= item.TemplateLibraryEntry;
如果(模板== NULL){
VIEWLINK = FALSE;
@ Html.DisplayFor(modelItem => item.TemplateName)
<环境监察及GT;(@ Resources.Entity.Environment.Removed)LT; / EM>
}
其他
{
@ Html.DisplayFor(modelItem => template.Name)
< A HREF =@ Url.Action(详细信息,DesignTemplate,新{ID = item.TemplateName})>< I类=发FA-FW FA-外部链接文本的方信息>&下; / I GT;&下; / A>
}
}
}
< / TD>
&所述; TD>
@if(!String.IsNullOrEmpty(item.UrlName))
{
VAR defaultProductUri = CustomerConfig.ToHostUri(Request.Url.Scheme,defaultHostHeader,Request.Url.Port,(isProduction:TEST /)+ item.UrlName?);
如果(VIEWLINK)
{
@ item.UrlName
< A HREF =@ defaultProductUri.ToString()称号=@ Resources.Entity.Product.ViewProduct目标=_空白>< I类=发FA-FW FA-外部链接方文-info>&下; / I GT;&下; / A>
}
其他
{
@ item.UrlName
}
}
< / TD>
&所述; TD>
@ { INT CNT = item.SubmittedForms.Where(PROD => prod.Order.IsProduction == isProduction).Count之间的();
@(cnt.ToString()+)
如果(CNT大于0)
{
< A HREF =@ Url.Action(指数,SubmittedForms,新的{过滤= item.Id})>
< I类=发FA-FW FA-外部链接方的文本信息>< I&GT /;
&所述; / A> }
}
< / TD>
< TD类=TEXT-NOWRAP>
@ item.ModificationDate.ToString(G)
< / TD>
< TD类=隐藏@((Model.id = NULL&放大器;&安培; item.Id == Model.id.Value)!?选择:的String.Empty)>
<跨度>
@if(String.IsNullOrEmpty(item.UrlName)及!&安培;!String.IsNullOrEmpty(item.FormName)){
@ Html.RouteLink(Resources.Action.Navigation。preVIEW,产品preVIEW,新的{PRODUCTURL = item.UrlName,customerSchema = custSchema},{新目标=_blank})
}
其他{@(Resources.Action.Navigation。preVIEW)}
| @ Html.ActionLink(Resources.Action.Navigation.Details,详细信息,新{ID = item.Id})
| @ Html.ActionLink(Resources.Action.Navigation.Edit,编辑,新{ID = item.Id})
< / SPAN>
< / TD> < / TR>
}
< / TBODY>
< /表>
< / DIV>
我现在有这样的:
$(文件)。就绪(函数(){
。无功表= $('#示例)的数据; $('#例如TBODY')。在('点击','TR',函数(){
如果($(本).hasClass('选择')){
$(本).removeClass('选择');
}
其他{
表$('tr.selected')removeClass移除('选择')。;
$(本).addClass('选择');
}
});
});
和我的观点:
< TD类=隐藏@((item.Id = 0)!?选择:的String.Empty)>
<跨度>
@if(String.IsNullOrEmpty(item.UrlName)及!&安培;!String.IsNullOrEmpty(item.FormName)){
@ Html.RouteLink(Resources.Action.Navigation。preVIEW,产品preVIEW,新的{PRODUCTURL = item.UrlName,customerSchema = custSchema},{新目标=_blank})
}
其他{@(Resources.Action.Navigation。preVIEW)}
| @ Html.ActionLink(Resources.Action.Navigation.Details,详细信息,新{ID = item.Id})
| @ Html.ActionLink(Resources.Action.Navigation.Edit,编辑,新{ID = item.Id})
< / SPAN>
< / TD>
但问题是,如果($(本).hasClass('选择')){
不被hitted
这是解决办法:
< TD类=隐藏@(item.Id ==(INT)(会话[ID]???0).dataTable SFS可选择SFS选择。表响应:的String.Empty)>< / TD>
那么,你应该只是传递一些参数为行通过控制器编辑后保存如 IsSelected
并在您查看
。我可以看到你这样做,但另一种方式:
RedirectToAction(指数,新的{页,ID = entry.Product.Id});
所以,在你查看你应该像这样做,我想:
< TD类=隐藏@((Model.id = NULL&放大器;&安培; item.id == Model.id.Value)!?选择:字符串。空)>
//你行code
< / TD>
I am using asp.net mvc4. And i have a grid where you can select a row and then you can edit the item. For example you are on page 3 and you want to edit a row on that page. So you select that row. But then after you have save the row you will return back to page 3 but the row is not selected anymore. I have this:
This is the Index page, where you can select a row. where you can choose what you want to do with the selected row.
<td class="hidden">
<span>
@if (!String.IsNullOrEmpty(item.UrlName) && !String.IsNullOrEmpty(item.FormName)) {
@Html.RouteLink(Resources.Action.Navigation.Preview, "ProductPreview", new { productUrl = item.UrlName, customerSchema = custSchema }, new { target = "_blank" })
}
else {
@(Resources.Action.Navigation.Preview)
}
| @Html.ActionLink(Resources.Action.Navigation.Details, "Details", new { id = item.Id })
| @Html.ActionLink(Resources.Action.Navigation.Edit, "Edit", new { id = item.Id })
</span>
</td>
and this is the Edit page:
with the two buttons:
<div class="row">
<div class="col-xs-12 ">
@Html.RenderNotifications()
</div>
<div class="col-xs-12 padding-bottom-10">
<button type="submit" value="Save" class="btn btn-success"><i class="fa fa-fw fa-check"></i> @Resources.Action.Navigation.Save</button>
<a href="@Resources.Action.Navigation.JSBack" class="btn btn-danger"><i class="fa fa-fw fa-times"></i>@Resources.Action.Navigation.Cancel </a>
</div>
</div>
Thank you
I am using this as table:
<table class="table table-striped table-bordered table-hover dataTable sfs-selectable sfs-col1-right-aligned">
And this is my javascript:
$(document).ready(function () {
var table = $('.table-responsive').DataTable();
$('#table-responsive tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
});
This is my Edit method:
public ActionResult Edit(int? id)
{
var page = Session["page"];
Session["page"] = page;
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Product product = db.Products.Find(id);
if (product == null)
{
throw new HttpException((int) HttpStatusCode.NotFound, null);
}
SetCreateEditProductLists(product, customerSchema);
EditProductModel editModel = new EditProductModel();
editModel.Product = product;
editModel.Db = db;
DeserializeAuthenticationSettings(editModel);
DeserializePaymentSettings(editModel);
DeserializeConnectors(editModel);
DeserializePrefillMappings(editModel);
ViewBag.Model = editModel;
return View(editModel);
}
This is my post Edit:
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(false)]
public ActionResult Edit(EditProductModel entry)
{
entry.Product.ModificationDate = DateTime.UtcNow;
//var page = TempData["page"];
//TempData["page"] = page;
//ViewBag.CurrentPage = 2;
if (ModelState.IsValid)
{
db.Entry(entry.Product).State = EntityState.Modified;
db.Entry(entry.Product).Property(model => model.Guid).IsModified = false;
db.Entry(entry.Product).Property(model => model.CreationDate).IsModified = false;
db.Entry(entry.Product).Property(model => model.IsProduction).IsModified = false;
entry.Product.IsProduction = StateHelper.IsTestMode() ? false : true;
HandleProductSelections(entry.Product);
SerializeAuthenticationSettings(entry);
SerializePaymentSettings(entry);
SerializeConnectors(entry);
SerializePrefillMappings(entry);
if (SaveDbChanges()) {
// Record an audit trail event for an updated product.
{
ATEvent atEvent = AuditTrailHelper.NewEvent(ATEventType.ProductUpdated, HttpContext, db.Schema, entry.Product);
atEvent.StringArg = entry.Product.Name;
ATEventLogger.Current.LogEvent(atEvent);
}
AddDelayedNotification(Resources.Entity.Environment.ItemSavedMessage, Notification.NotificationType.Success);
//return RedirectToAction("Index", new { page = page });
//var page = TempData["page"];
//TempData["page"] = page;
var page = Session["page"];
Session["page"] = page;
var id = Session["id"];
Session["id"] = id;
return RedirectToAction("Index", new { page, id = entry.Product.Id });
}
}
AddDelayedNotification(Resources.Entity.Environment.ItemNotSavedError, Notification.NotificationType.Error);
return Edit(entry.Product.Id);
}
this is the Index view:
<div class="table-responsive" id="example">
<table class="table table-striped table-bordered table-hover dataTable sfs-selectable sfs-col1-right-aligned" id="example">
<thead>
<tr>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.Id).ToString(), "Sort-Product", new { sortColumn = "id", sortOrder = (ViewBag.sortColumn == "id" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("id", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.Name).ToString(), "Sort-Product", new { sortColumn = "name", sortOrder = (ViewBag.sortColumn == "name" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("name", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.IsEnabled).ToString(), "Sort-Product", new { sortColumn = "enabled", sortOrder = (ViewBag.sortColumn == "enabled" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("enabled", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.FormName).ToString(), "Sort-Product", new { sortColumn = "formname", sortOrder = (ViewBag.sortColumn == "formname" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("formname", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.TemplateName).ToString(), "Sort-Product", new { sortColumn = "design", sortOrder = (ViewBag.sortColumn == "design" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("design", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Resources.Entity.Product.PublicUrl, "Sort-Product", new { sortColumn = "urlname", sortOrder = (ViewBag.sortColumn == "urlname" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("urlname", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.DisplayNameFor(model => firstItem.SubmittedForms)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.ModificationDate).ToString(), "Sort-Product", new { sortColumn = "modified", sortOrder = (ViewBag.sortColumn == "modified" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString })
@ViewHelper.GetSortIndicator("modified", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th class="hidden"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsEnabled)
</td>
<td>
@{
bool viewLink = item.IsEnabled;
if (!String.IsNullOrEmpty(item.FormName))
{
var form = item.FormLibraryEntry;
if (form == null) {
viewLink = false;
@Html.DisplayFor(modelItem => item.FormName)
<em>(@Resources.Entity.Environment.Removed)</em>
}
else
{
@Html.DisplayFor(modelItem => form.Name)
<a href="@Url.Action("Details", "FormLibrary", new { id = item.FormName })"><i class="fa fa-fw fa-external-link-square text-info"></i></a>
}
}
}
</td>
<td>
@{
if (!String.IsNullOrEmpty(item.TemplateName))
{
var template = item.TemplateLibraryEntry;
if (template == null) {
viewLink = false;
@Html.DisplayFor(modelItem => item.TemplateName)
<em>(@Resources.Entity.Environment.Removed)</em>
}
else
{
@Html.DisplayFor(modelItem => template.Name)
<a href="@Url.Action("Details", "DesignTemplate", new { id = item.TemplateName })"><i class="fa fa-fw fa-external-link-square text-info"></i></a>
}
}
}
</td>
<td>
@if (!String.IsNullOrEmpty(item.UrlName))
{
var defaultProductUri = CustomerConfig.ToHostUri(Request.Url.Scheme, defaultHostHeader, Request.Url.Port, (isProduction ? "" : "TEST/") + item.UrlName);
if (viewLink)
{
@item.UrlName
<a href="@defaultProductUri.ToString()" title="@Resources.Entity.Product.ViewProduct" target="_blank"><i class="fa fa-fw fa-external-link-square text-info"></i></a>
}
else
{
@item.UrlName
}
}
</td>
<td>
@{
int cnt = item.SubmittedForms.Where(prod => prod.Order.IsProduction == isProduction).Count();
@(cnt.ToString() + " ")
if (cnt > 0)
{
<a href="@Url.Action("Index", "SubmittedForms", new { filter = item.Id })">
<i class="fa fa-fw fa-external-link-square text-info"></i>
</a>
}
}
</td>
<td class="text-nowrap">
@item.ModificationDate.ToString("G")
</td>
<td class="hidden @((Model.id != null && item.Id == Model.id.Value)? "selected" : String.Empty)">
<span>
@if (!String.IsNullOrEmpty(item.UrlName) && !String.IsNullOrEmpty(item.FormName)) {
@Html.RouteLink(Resources.Action.Navigation.Preview, "ProductPreview", new { productUrl = item.UrlName, customerSchema = custSchema }, new { target = "_blank" })
}
else { @(Resources.Action.Navigation.Preview) }
| @Html.ActionLink(Resources.Action.Navigation.Details, "Details", new { id = item.Id })
| @Html.ActionLink(Resources.Action.Navigation.Edit, "Edit", new { id = item.Id })
</span>
</td>
</tr>
}
</tbody>
</table>
</div>
I have it now like this:
$(document).ready(function () {
var table = $('#example').data;
$('#example tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
});
and my view:
<td class="hidden @((item.Id != 0)? "selected" : String.Empty)">
<span>
@if (!String.IsNullOrEmpty(item.UrlName) && !String.IsNullOrEmpty(item.FormName)) {
@Html.RouteLink(Resources.Action.Navigation.Preview, "ProductPreview", new { productUrl = item.UrlName, customerSchema = custSchema }, new { target = "_blank" })
}
else { @(Resources.Action.Navigation.Preview) }
| @Html.ActionLink(Resources.Action.Navigation.Details, "Details", new { id = item.Id })
| @Html.ActionLink(Resources.Action.Navigation.Edit, "Edit", new { id = item.Id })
</span>
</td>
But the problem is that if ($(this).hasClass('selected')) {
is not be hitted
This was the solution:
<td class="hidden @(item.Id == (int)(Session["Id"] ?? 0) ? ".dataTable sfs-selectable sfs-selected .table-responsive" : String.Empty) ">
</td>
Well, you should just pass some param for row through controller after edit save like IsSelected
and on your View
. And i can see you do it but the other way:
RedirectToAction("Index", new { page, id = entry.Product.Id });
So on your View you should do it like this, i guess:
<td class="hidden @((Model.id != null && item.id == Model.id.Value)? "selected" : String.Empty)">
// Your row code
</td>
这篇关于留在选择行后提交(保存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!