This question is locked. New answers and comments are not allowed.
I have a lookup that frequently contains a " (double-quote) in the display value to represent inches. This is causing all kinds of problems in my grid-->detail grids. Unfortunately, I can't figure out where to encode the display. I could encode the data when I store it in the database, but I would prefer to handle the encoding in the view.
How can I html.encode the display value for a foreign key column?
How can I html.encode the display value for a foreign key column?
5 Answers, 1 is accepted
0
Matthew
Top achievements
Rank 1
answered on 10 Jan 2012, 09:36 PM
The problem has become more worrysome. I have encoded the information and the problem remains. In my controller I pass the data to the view as follows:
I have stepped through the code and confirmed the data is encoded properly.
In the view I have the foreignkey column defined as follows:
Note that the data for the foreignkey columns comes from ViewData["hooks"]
So now I'm very concerned about how to fix this problem.
ViewData["hooks"] = LineDB.Hooks .Select(e => new { HookId = e.HookId, HookName = HttpUtility.HtmlEncode(e.HookName) }) .OrderBy(e => HttpUtility.HtmlEncode(e.HookName));I have stepped through the code and confirmed the data is encoded properly.
In the view I have the foreignkey column defined as follows:
c.ForeignKey(h => h.HookId, (IEnumerable)ViewData["hooks"], "HookId", "HookName").Width(210).Title("Hook #");Note that the data for the foreignkey columns comes from ViewData["hooks"]
So now I'm very concerned about how to fix this problem.
0
Matthew
Top achievements
Rank 1
answered on 10 Jan 2012, 10:39 PM
More information: Here is the string that is causing problems:
8" Standard Hook
If I encode the string I get:
8\" Standard Hook
This does not solve the problem.
If I replace the double quotes with:
8" Standard Hook
The problem remains. If, however, if I replace the double quote with two single quotes, the problem goes away:
8'' Standard Hook
This is not an acceptable solution because I don't have control over what the user enters, and this simply is an unreasonable requirement in order to use the application.
8" Standard Hook
If I encode the string I get:
8\" Standard Hook
This does not solve the problem.
If I replace the double quotes with:
8" Standard Hook
The problem remains. If, however, if I replace the double quote with two single quotes, the problem goes away:
8'' Standard Hook
This is not an acceptable solution because I don't have control over what the user enters, and this simply is an unreasonable requirement in order to use the application.
0
Hi,
Rosen
the Telerik team
I'm afraid that I'm unable to observe any unexpected behavior using the provided details. Please take a look at the attached test project, maybe I'm missing something obvious. Also could you provide a bit more information about the what is the exact problem you are facing?
Greetings,Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Matthew
Top achievements
Rank 1
answered on 11 Jan 2012, 02:23 PM
I'll post the code and I apologize for the complexity of the page. It's a master/detail grid with a tab control. The problem shows up in the detail grid. When I click the button to add a new record to the detail grid, it adds a record to the Master grid? Strange. In addition, I can't click on any of the tabs in the detail section. If I remove the double-quote everything works as expected.
View:
Controller:
View:
@model IEnumerable<Line.OpenAccess.Parts>@using System.Collections; @using Line.OpenAccess;@using Telerik.Web.Mvc.UI;@{ ViewBag.Title = "Parts"; Layout = "~/Views/Shared/_Layout.cshtml";}<h2>@ViewBag.Title</h2>@(Html.Telerik().Grid(Model) .Name("grid1") .DataKeys(k => k.Add(o => o.PartId)) .Columns(c => { c.Bound(h => h.PartNum).Width(90).Title("Number"); c.Bound(h => h.Revision).Width(60).Title("Rev"); c.Bound(h => h.PiecesPer).Width(60).Title("QTY"); c.ForeignKey(h => h.PowderId, (IEnumerable)ViewData["powders"], "PowderId", "PowderName").Width(110).Title("Powder").UIHint("YourEditorName") ; c.Bound(h => h.LineSpeed).Width(70).Title("Speed"); c.Bound(h => h.OvenTemp).Width(60).Title("Temp"); c.Bound(h => h.HookGap).Width(90).Title("Hook Gap"); c.Bound(h => h.Wash1).Width(100).Title("Washers: 1") .ClientTemplate("<input type='checkbox' name='Wash1' disabled='disabled' <#= Wash1? checked='checked' : '' #> />"); c.Bound(h => h.Wash2).Width(40).Title("2") .ClientTemplate("<input type='checkbox' name='Wash2' disabled='disabled' <#= Wash2? checked='checked' : '' #> />"); c.Bound(h => h.Wash3).Width(40).Title("3") .ClientTemplate("<input type='checkbox' name='Wash3' disabled='disabled' <#= Wash3? checked='checked' : '' #> />"); c.Bound(h => h.Wash4).Width(40).Title("4") .ClientTemplate("<input type='checkbox' name='Wash4' disabled='disabled' <#= Wash4? checked='checked' : '' #> />"); c.Bound(h => h.Wash5).Width(40).Title("5") .ClientTemplate("<input type='checkbox' name='Wash5' disabled='disabled' <#= Wash5? checked='checked' : '' #> />"); c.Bound(h => h.Wash6).Width(40).Title("6") .ClientTemplate("<input type='checkbox' name='Wash6' disabled='disabled' <#= Wash6? checked='checked' : '' #> />"); c.Bound(h => h.Wash7).Width(40).Title("7") .ClientTemplate("<input type='checkbox' name='Wash7' disabled='disabled' <#= Wash7? checked='checked' : '' #> />"); c.Bound(h => h.Active).Width(60) .ClientTemplate("<input type='checkbox' name='Active' disabled='disabled' <#= Active? checked='checked' : '' #> />"); c.Command(s => { s.Delete().ButtonType(GridButtonType.Image); }); c.Bound(h => h.PartId).ReadOnly().Hidden(true); //Hidden columns should be last }) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.ImageAndText); commands.SubmitChanges().ButtonType(GridButtonType.ImageAndText); }) .DataBinding(d => { d.Ajax() .Update("AjaxGridUpdates", "Parts") .Select("_AjaxBinding", "Parts"); //VERY important }) .ClientEvents(e => { e.OnDataBinding("Grid_onDataBinding"); e.OnError("Grid_onError"); }) .Editable(editing => editing.Mode(GridEditMode.InCell)) .Pageable(pager => pager.PageSize(40)) .Sortable() .Filterable() .KeyboardNavigation() .Scrollable(scroll => scroll.Height(500)) .HtmlAttributes(new { style = "width:1040px;" }) //-------------------------------------------- // Details View //-------------------------------------------- .DetailView(details => details.ClientTemplate( Html.Telerik().TabStrip() .Name("TabStrip_<#= PartId #>") .SelectedIndex(0) .Items(items => { ////////////////////////////////////////////////// //Plugs Grid ////////////////////////////////////////////////// items.Add().Text("Plugs").Content( Html.Telerik().Grid<Part_Plugs>() .Name("Plugs_<#= PartId #>") .DataKeys(dataKeys => dataKeys.Add(m => m.PartPlugId)) .DataBinding(d => { d.Ajax() .Select("_ReturnPart_Plugs", "Parts", new { PartId = "<#= PartId #>" }) .Update("_UpdatePart_Plugs", "Parts", new { PartId = "<#= PartId #>" }); }) .Columns(c => { c.ForeignKey(h => h.PlugId, (IEnumerable)ViewData["plugs"], "PlugId", "PlugName").Width(300).Title("Plug #"); c.Bound(h => h.PlugQty).Title("Qty"); c.Command(s => { s.Delete().ButtonType(GridButtonType.Image); }); c.Bound(h => h.PartPlugId).Hidden(true); c.Bound(h => h.PartId).Hidden(true); }) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.ImageAndText); commands.SubmitChanges().ButtonType(GridButtonType.ImageAndText); }) .ClientEvents(e => { e.OnDataBinding("Grid_onDataBinding"); e.OnError("Grid_onError"); }) .Editable(e => e.Mode(GridEditMode.InCell)) .Sortable() .KeyboardNavigation() .Scrollable(scroll => scroll.Height(200)) .HtmlAttributes(new { style = "width:400px;" }) .ToString()); ////////////////////////////////////////////////// //HooKs Grid ////////////////////////////////////////////////// items.Add().Text("Hooks").Content( Html.Telerik().Grid<Part_Hooks>() .Name("Hooks_<#= PartId #>") .DataKeys(dataKeys => dataKeys.Add(m => m.PartHookId)) .DataBinding(d => { d.Ajax() .Select("_ReturnPart_Hooks", "Parts", new { PartId = "<#= PartId #>" }) .Update("_UpdatePart_Hooks", "Parts", new { PartId = "<#= PartId #>" }); }) .Columns(c => { c.ForeignKey(h => h.HookId, (IEnumerable)ViewData["hooks"], "HookId", "HookName").Width(210).Title("Hook #"); c.Bound(h => h.HookQty).Title("Qty"); c.Command(s => { s.Delete().ButtonType(GridButtonType.Image); }); c.Bound(h => h.PartHookId).Hidden(true); c.Bound(h => h.PartId).Hidden(true); }) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.ImageAndText); commands.SubmitChanges().ButtonType(GridButtonType.ImageAndText); }) .ClientEvents(e => { e.OnDataBinding("Grid_onDataBinding"); e.OnError("Grid_onError"); }) .Editable(e => e.Mode(GridEditMode.InCell)) .Sortable() .KeyboardNavigation() .Scrollable(scroll => scroll.Height(200)) .HtmlAttributes(new { style = "width:390px;" }) .ToString() ); ////////////////////////////////////////////////// //WeldNuts Grid ////////////////////////////////////////////////// items.Add().Text("Weldnuts").Content( Html.Telerik() .Grid<Part_WeldNuts>() .Name("WeldNuts_<#= PartId #>") .DataKeys(dataKeys => dataKeys.Add(m => m.PartWeldNutId)) .DataBinding(d => { d.Ajax() .Select("_ReturnPart_WeldNuts", "Parts", new { PartId = "<#= PartId #>" }) .Update("_UpdatePart_WeldNuts", "Parts", new { PartId = "<#= PartId #>" }); }) .Columns(c => { c.ForeignKey(h => h.WeldNutId, (IEnumerable)ViewData["weldnuts"], "WeldNutId", "WeldNutName").Width(210).Title("If Weldnut size is"); c.ForeignKey(h => h.TapId, (IEnumerable)ViewData["taps"], "TapId", "TapName").Width(210).Title("Use Tap size"); c.Command(s => { s.Delete().ButtonType(GridButtonType.Image); }); c.Bound(h => h.PartWeldNutId).Hidden(true); c.Bound(h => h.PartId).Hidden(true); }) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.ImageAndText); commands.SubmitChanges().ButtonType(GridButtonType.ImageAndText); }) .ClientEvents(e => { e.OnDataBinding("Grid_onDataBinding"); e.OnError("Grid_onError"); }) .Editable(e => e.Mode(GridEditMode.InCell)) .Sortable() .KeyboardNavigation() .Scrollable(scroll => scroll.Height(200)) .HtmlAttributes(new { style = "width:490px;" }) .ToString() ); ////////////////////////////////////////////////// //Stations ////////////////////////////////////////////////// items.Add().Text("Load").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 1 }); items.Add().Text("Mask").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 2 }); items.Add().Text("Paint").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 3 }); items.Add().Text("Un-load/Pack").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 4 }); items.Add().Text("Station 5").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 5 }).Enabled(false); items.Add().Text("Station 6").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 6 }).Enabled(false); items.Add().Text("Station 7").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 7 }).Enabled(false); items.Add().Text("Station 8").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 8 }).Enabled(false); items.Add().Text("Station 9").LoadContentFrom("StationEditor", "Parts", new { PartId = "<#= PartId #>", StationId = 9 }).Enabled(false); }) .ToHtmlString() )))<br /><script type="text/javascript"> function Grid_onError(args) { if (args.textStatus == "modelstateerror" && args.modelState) { var message = "Errors:\n"; $.each(args.modelState, function (key, value) { if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); } }); alert(message); } } function Grid_onDataBinding(e) { var grid = $(this).data('tGrid'); if (grid.hasChanges()) { if (!confirm('You are going to lose any unsaved changes. Are you sure?')) { e.preventDefault(); } } } function saveToDatabase(_PartId, _StationId) { var editorName = "Editor_" + _PartId + "_" + _StationId var editor = $("#" + editorName).data("tEditor"); var data = { PartId: _PartId, StationId: _StationId, instruction: editor.value() }; $.ajax({ url: "Parts/Save2DB", data: data, type: "POST" }); alert("Saved"); }</script>Controller:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using Line.OpenAccess;using Telerik.Web.Mvc;using System.Collections;namespace Line.Controllers{ public class PartsController : Controller { LineEntities LineDB = new LineEntities(); //View [GridAction] public ActionResult Index() { PopulateComboBoxes(); //var Parts = LineDB.Parts.ToList(); //return View(Parts); return View(); } private void PopulateComboBoxes() { //ViewData["colors"] = LineDB.HtmlColors.Select(e => new { ColorId = e.ColorId, HexColor = e.HexCode }); ViewData["colors"] = LineDB.HtmlColors .Select(e => new { ColorId = e.ColorId, HtmlName = HttpUtility.HtmlEncode(e.HtmlName) }) .OrderBy(e => HttpUtility.HtmlEncode(e.HtmlName)); ViewData["powders"] = LineDB.Powders .Select(e => new { PowderId = e.PowderId, PowderName = HttpUtility.HtmlEncode(e.PowderName) }) .OrderBy(e => HttpUtility.HtmlEncode(e.PowderName)); ViewData["hooks"] = LineDB.Hooks .Select(e => new { HookId = e.HookId, HookName = e.HookName }) .OrderBy(e => e.HookName); ViewData["plugs"] = LineDB.Plugs .Select(e => new { PlugId = e.PlugId, PlugName = HttpUtility.HtmlEncode(e.PlugName) }) .OrderBy(e => HttpUtility.HtmlEncode(e.PlugName)); ViewData["weldnuts"] = LineDB.WeldNuts .Select(e => new { WeldNutId = e.WeldNutId, WeldNutName = HttpUtility.HtmlEncode(e.WeldNutName) }) .OrderBy(e => HttpUtility.HtmlEncode(e.WeldNutName)); ViewData["taps"] = LineDB.Taps .Select(e => new { TapId = e.TapId, TapName = HttpUtility.HtmlEncode(e.TapName) }) .OrderBy(e => HttpUtility.HtmlEncode(e.TapName)); //ViewData["notes"] = "This is a test"; } ///////////////////////////////////////////////////////////////////////////////// // Ajax Binding Versions ///////////////////////////////////////////////////////////////////////////////// //Ajax Binding [GridAction] public ActionResult _AjaxBinding() { return View(new GridModel<Parts> { Data = this.LineDB.Parts.ToList() }); } // //Updates [GridAction] [HttpPost] public ActionResult AjaxGridUpdates( IEnumerable<Parts> inserted, IEnumerable<Parts> updated, IEnumerable<Parts> deleted) { //Inserted if (inserted != null) { foreach (var Part in inserted) { //Add new record this.LineDB.Add(Part); this.LineDB.SaveChanges(); } } //Updated if (updated != null) { foreach (var Part in updated) { //1. Load the original Part from the database var originalParts = this.LineDB.Parts.FirstOrDefault(c => c.PartId == Part.PartId); if (originalParts != null) { //2. Update with new data originalParts.PartNum = Part.PartNum; originalParts.Revision = Part.Revision; originalParts.PiecesPer = Part.PiecesPer; originalParts.PowderId = Part.PowderId; originalParts.LineSpeed = Part.LineSpeed; originalParts.OvenTemp = Part.OvenTemp; originalParts.HookGap = Part.HookGap; originalParts.Wash1 = Part.Wash1; originalParts.Wash2 = Part.Wash2; originalParts.Wash3 = Part.Wash3; originalParts.Wash4 = Part.Wash4; originalParts.Wash5 = Part.Wash5; originalParts.Wash6 = Part.Wash6; originalParts.Wash7 = Part.Wash7; originalParts.Active = Part.Active; //3. Save Changes this.LineDB.SaveChanges(); } } } //Deleted if (deleted != null) { foreach (var Part in deleted) { //1. Load original Part from the databgase Parts originalPart = this.LineDB.Parts.FirstOrDefault(c => c.PartId == Part.PartId); if (originalPart != null) { //2. Pass it to the delete method this.LineDB.Delete(originalPart); //3. Save changes this.LineDB.SaveChanges(); } } } return View(new GridModel<Parts> { Data = LineDB.Parts.ToList() }); } /// //////////////////////////////////////////////////////////////////////////////////////////////////////// /// Part_Hooks /// //////////////////////////////////////////////////////////////////////////////////////////////////////// [GridAction] public ActionResult _ReturnPart_Hooks(Int64 PartId) { var part_hooks = from o in new LineEntities().Part_Hooks where o.PartId == PartId select new { PartHookId = o.PartHookId, PartId = o.PartId, HookId = o.HookId, HookQty = o.HookQty }; return View(new GridModel(part_hooks)); } [GridAction] public ActionResult _UpdatePart_Hooks( Int64 PartId, IEnumerable<Part_Hooks> inserted, IEnumerable<Part_Hooks> updated, IEnumerable<Part_Hooks> deleted) { //Inserted if (inserted != null) { foreach (var Part_Hook in inserted) { //Copy the PartId from parent grid Part_Hook.PartId = PartId; //Save record this.LineDB.Add(Part_Hook); this.LineDB.SaveChanges(); } } //Updated if (updated != null) { foreach (var Part_Hook in updated) { //1. Load the original Part from the database var originalPart_Hook = this.LineDB.Part_Hooks.FirstOrDefault(c => c.PartHookId == Part_Hook.PartHookId); if (originalPart_Hook != null) { //2. Update with new data originalPart_Hook.HookId = Part_Hook.HookId; originalPart_Hook.HookQty = Part_Hook.HookQty; //3. Save Changes this.LineDB.SaveChanges(); } } } //Deleted if (deleted != null) { foreach (var Part_Hook in deleted) { //1. Load original Part from the databgase Part_Hooks originalPart_Hook = LineDB.Part_Hooks.FirstOrDefault(c => c.PartHookId == Part_Hook.PartHookId); if (originalPart_Hook != null) { //2. Pass it to the delete method LineDB.Delete(originalPart_Hook); //3. Save changes LineDB.SaveChanges(); } } } //Get list after all changes var part_hooks = from o in new LineEntities().Part_Hooks where o.PartId == PartId select new { PartHookId = o.PartHookId, PartId = o.PartId, HookId = o.HookId, HookQty = o.HookQty }; return View(new GridModel(part_hooks)); } /// //////////////////////////////////////////////////////////////////////////////////////////////////////// /// Part_Plugs /// //////////////////////////////////////////////////////////////////////////////////////////////////////// [GridAction] public ActionResult _ReturnPart_Plugs(Int64 PartId) { var part_Plugs = from o in new LineEntities().Part_Plugs where o.PartId == PartId select new { PartPlugId = o.PartPlugId, PartId = o.PartId, PlugId = o.PlugId, PlugQty = o.PlugQty }; return View(new GridModel(part_Plugs)); } [GridAction] public ActionResult _UpdatePart_Plugs( Int64 PartId, IEnumerable<Part_Plugs> inserted, IEnumerable<Part_Plugs> updated, IEnumerable<Part_Plugs> deleted) { //Inserted if (inserted != null) { foreach (var Part_Plug in inserted) { //Copy the PartId from parent grid Part_Plug.PartId = PartId; //Save record this.LineDB.Add(Part_Plug); this.LineDB.SaveChanges(); } } //Updated if (updated != null) { foreach (var Part_Plug in updated) { //1. Load the original Part from the database var originalPart_Plug = this.LineDB.Part_Plugs.FirstOrDefault(c => c.PartPlugId == Part_Plug.PartPlugId); if (originalPart_Plug != null) { //2. Update with new data originalPart_Plug.PlugId = Part_Plug.PlugId; originalPart_Plug.PlugQty = Part_Plug.PlugQty; //3. Save Changes this.LineDB.SaveChanges(); } } } //Deleted if (deleted != null) { foreach (var Part_Plug in deleted) { //1. Load original Part from the databgase Part_Plugs originalPart_Plug = LineDB.Part_Plugs.FirstOrDefault(c => c.PartPlugId == Part_Plug.PartPlugId); if (originalPart_Plug != null) { //2. Pass it to the delete method LineDB.Delete(originalPart_Plug); //3. Save changes LineDB.SaveChanges(); } } } //Get list after all changes var part_Plugs = from o in new LineEntities().Part_Plugs where o.PartId == PartId select new { PartPlugId = o.PartPlugId, PartId = o.PartId, PlugId = o.PlugId, PlugQty = o.PlugQty }; return View(new GridModel(part_Plugs)); } /// //////////////////////////////////////////////////////////////////////////////////////////////////////// /// Part_WeldNuts /// //////////////////////////////////////////////////////////////////////////////////////////////////////// [GridAction] public ActionResult _ReturnPart_WeldNuts(Int64 PartId) { var part_WeldNuts = from o in new LineEntities().Part_WeldNuts where o.PartId == PartId select new { PartWeldNutId = o.PartWeldNutId, PartId = o.PartId, WeldNutId = o.WeldNutId, TapId = o.TapId }; return View(new GridModel(part_WeldNuts)); } [GridAction] public ActionResult _UpdatePart_WeldNuts( Int64 PartId, IEnumerable<Part_WeldNuts> inserted, IEnumerable<Part_WeldNuts> updated, IEnumerable<Part_WeldNuts> deleted) { //Inserted if (inserted != null) { foreach (var Part_WeldNut in inserted) { //Copy the PartId from parent grid Part_WeldNut.PartId = PartId; //Save record this.LineDB.Add(Part_WeldNut); this.LineDB.SaveChanges(); } } //Updated if (updated != null) { foreach (var Part_WeldNut in updated) { //1. Load the original Part from the database var originalPart_WeldNut = this.LineDB.Part_WeldNuts.FirstOrDefault(c => c.PartWeldNutId == Part_WeldNut.PartWeldNutId); if (originalPart_WeldNut != null) { //2. Update with new data originalPart_WeldNut.WeldNutId = Part_WeldNut.WeldNutId; originalPart_WeldNut.TapId = Part_WeldNut.TapId; //3. Save Changes this.LineDB.SaveChanges(); } } } //Deleted if (deleted != null) { foreach (var Part_WeldNut in deleted) { //1. Load original Part from the databgase Part_WeldNuts originalPart_WeldNut = LineDB.Part_WeldNuts.FirstOrDefault(c => c.PartWeldNutId == Part_WeldNut.PartWeldNutId); if (originalPart_WeldNut != null) { //2. Pass it to the delete method LineDB.Delete(originalPart_WeldNut); //3. Save changes LineDB.SaveChanges(); } } } //Get list after all changes var part_WeldNuts = from o in new LineEntities().Part_WeldNuts where o.PartId == PartId select new { PartWeldNutId = o.PartWeldNutId, PartId = o.PartId, WeldNutId = o.WeldNutId, TapId = o.TapId }; return View(new GridModel(part_WeldNuts)); } /// ///////////////////////////////////////////////// /// Editor /// ///////////////////////////////////////////////// public ActionResult StationEditor(Int64 PartId, int StationId) { Part_Instructions PI = LineDB.Part_Instructions.FirstOrDefault(c => c.PartId == PartId && c.StationId == StationId); //Get/Set values ViewData["PartId"] = PartId.ToString(); ViewData["StationId"] = StationId.ToString(); if (PI == null) { ViewData["Notes"] = "Existing record Not found"; } else { ViewData["Notes"] = HttpUtility.HtmlDecode(PI.Instruction); } return PartialView(); } public ActionResult SaveStation(String PartId, String StationId, string EditorValue) { Int64 partId = Int64.Parse(PartId); int stationId = int.Parse(StationId); string instruction = Request["Editor_" + PartId + "_" + StationId]; //1. Load the original Part from the database Part_Instructions PI = LineDB.Part_Instructions.FirstOrDefault(c => c.PartId == partId && c.StationId == stationId); //New Instruction if (PI == null) { //Copy the PartId from parent grid PI = new Line.OpenAccess.Part_Instructions(); PI.PartId = partId; PI.StationId = stationId; PI.Instruction = instruction; //Save record this.LineDB.Add(PI); this.LineDB.SaveChanges(); } //Updated Instruction else { //2. Update with new data PI.Instruction = instruction; //3. Save Changes this.LineDB.SaveChanges(); } PopulateComboBoxes(); return View("Index"); } [HttpPost] public void Save2DB(Int64 partId, int stationId, string instruction) { //1. Load the original Part from the database Part_Instructions PI = LineDB.Part_Instructions.FirstOrDefault(c => c.PartId == partId && c.StationId == stationId); //New Instruction if (PI == null) { //Copy the PartId from parent grid PI = new Line.OpenAccess.Part_Instructions(); PI.PartId = partId; PI.StationId = stationId; PI.Instruction = instruction; //Save record this.LineDB.Add(PI); this.LineDB.SaveChanges(); } //Updated Instruction else { //2. Update with new data PI.Instruction = instruction; //3. Save Changes this.LineDB.SaveChanges(); } } }}0
Hi Matthew,
Rosen
the Telerik team
I'm afraid that I'm unable to tell what may caused such issue looking at the provided details. Therefore, it will be appreciated if you could either modify the sample I have provided in my previous message, or sent us a small runnable sample in which this can be observed.
All the best,Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now