ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Spreadsheet grid ClientFormatFunc not working
Title:
B
I
{code}
?
I have several cells on the grid that should be available for update as per the spreadsheet demo, but the ClientFormatFunc seems not to understand the value that the grid has so it is always setting the input/text with the default value (in my case it is a 0). But the other issue is that when the input/text changes I get an red error on the top corner indicating "unexpected error occured" and it doesn't even invoques the Save method. Column: `new Column { Bind = "Forecast", Width = 55, Header = "Feb-21", CssClass = "forecaststyle", ClientFormatFunc = "txt" },` Script: function txt(model, name) { var val = model[name]; if (!val) val = "0"; return "<input type='number' name='" + name + "' value='" + awef.encode(val) + "'/>"; } $(function () { var g = $('#GridForecastCases'); var api = g.data('api'); g.on('change', 'input', function () { var input = $(this); var model = utils.model(input.closest('.awe-row')); var prop = input.attr("name"); model[prop] = input.val(); // using awe.ajx instead of $.ajax to get the antiforgery token added automatically + error handling awe.ajx('@(Url.Action("Save", "Forecast"))', awe.srl({ id: model.Id, name: prop, value: model[prop] })) .done(); }); }); Thanks
Save Changes
Cancel
AM
asked at 26 Feb 2021
Debugging I see the correct information for model and name, but then val is undefined: MODEL {id: "12|775|AB", brandId: 12, province: "AB", productId: 775, productName: "BLAH", …} brandId: 12 forecast: 0 forecastPlus1: 44 forecastPlus2: 0 ... NAME ForecastPlus1 After `var val = model[name];` val = undefined
at 26 Feb 2021
AM
I presume the actual property name starts with an `f` not `F` have a look at this: https://github.com/aspnet/Mvc/issues/4283 in our main demo in `Startup.cs` we change the JSON behaviour to undo the auto camelCase transform
at 26 Feb 2021
Omu
Thanks, changing the Startup.cs to match your demo fixed the first issue. thanks. Now will focus on the other one...
at 26 Feb 2021
AM
So the Debugger is also showing me the expected result: I get: `awe.ajx('/Forecast/SaveForecast', awe.srl({ id: model.Id, name: prop, value: model[prop] }));` and the model, the prop and the model[prop] have the correct value. In my ForecastController the "SaveForecast" method exists but it never makes it; somehow it gets lost.. What should I look for to understand what is going on?
at 27 Feb 2021
AM
open Chrome Console (F12) -> Network tab -> XHR make a change in an input to trigger the save look in the console for the request click on it and you will see the data sent and the response from the server
at 27 Feb 2021
Omu
I do get 404 Not Found, but everything seems correct. The only thing I can think of is that my Id is a string and not an integer which is not something I can change. So the controler has: `public IActionResult SaveForecast(string id, string name, string value)`
at 05 Mar 2021
AM
maybe you're missing the `[HttpPost]` on the action
at 05 Mar 2021
Omu
Hmmm... will try that, but in the spreadsheet demo that I downloaded and on your online one, the controller code doesn't contain it
at 05 Mar 2021
AM
I guess this worked. Maybe you can explain to me why your demos don't have this? Thanks for your help
at 05 Mar 2021
AM
usually you can call a get action using a post request, I would have to have access to your entire codebase to know why this worked, or maybe you made another change that fixed it
at 05 Mar 2021
Omu
Well, I am more practical than perfect... it works which is what matters to me. Thanks for your help and for being on top of your customers' questions. I really appreciate it
at 05 Mar 2021
AM
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK