last day (14 days later) » 

2:39 PM
0
A: Passing DataTable from controler to PartialView

SippyYou will probably need to use AJAX for this. You can bind the AJAX request below to anything you like. It sounds like you may need to bind it to your onload event and a refresh button click event. AJAX example: $.post('@Url.Content("~/Graph/_GetDailyOutput")', function( data ) { $( "#dvCate...

 
PartialView is not recognized by intellisense, are you mean PartialViewResult? That returns me an error: Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
 
Yep, sorry, my bad!
 
I still have the same error
 
What is it exactly that's throwing this error? @Html.Action?
 
Yes @Html.Action, But it _GetDailyOutput is completed
 
2:39 PM
Ah. In that case, call your ajax when the page loads instead.
 
Sorry I think I misunderstood you, I didn't use Ajax yet, only the Action
wow I didn't know about the chat
 
:P
Super useful, lots of very knowledgeable people here as well!
 
yes agree
 
Okay so before we do anything, try changing it from @Html.Action to @Html.RenderAction
 
that's in error as well
 
2:42 PM
Same error?
 
different
It actually fails when it calls @Html.RenderAction("GetDailyOutput", "Graph")
 
Oh ffs.
I'm dumb
_GetDailyOutput
 
where before it went to controller and process everything and fails when returning PartialView
no you are not, I have change it
 
Ah
 
I change name in Controler and in the partailView to GetDailyOutput
 
2:44 PM
I see
And what is your partial view file actually named?
 
GetDailyOutput as well
 
Okay
Let me see if I can reproduce, hold on
Which version of MVC are you using?
 
5.2
Apparently I have to use @{Html.RenderAction ... and not @Html.RenderAction ...
but this still give me the same error as @Html.Action ...
 
Makes no difference
VS is messing about sorry
 
there is something wrong with my partial view
just edited it to:
@model System.Data.DataTable
@using System.Data
<p>test</p>
and it works
 
2:59 PM
Ah
Yeah I'm just realising this
Thank you ASP.NET for the non-descript error message ..
 
:)
 
Okay so use @Html.Action cos RenderAction doesn't work
I'll try and help you figure out why your partialview doesn't work cos I have nothing else to do! :D
 
it does work if I use { and }
I think I found it
 
Wait really?
RenderAction works because of that?
 
yes
 
3:01 PM
WAAAT
 
I hnow I'm surprise as well
 
It puts my project into an infinite loop lol
 
I n my partial I didn't put Model.Columns and Model.Rows just Model
 
I would advise using Action because I think something strange is happening in your application, but you can use whatever works I guess.
Ohhhhhhhhh
That might be why, yeah.
You should probably edit your question and add them, if that works
 
Yes I will, I need to do the Ajax call now, could you assist me with that?
 
3:04 PM
Sure
 
ok so I have several charts which use Ajax call just need to add binding to that partialView
function onCriteriaChange() {
var DailyOutputByHourDem = $("#DailyOutputByHourDem").data("kendoChart");
var DailyOutputByHourFFS = $("#DailyOutputByHourFFS").data("kendoChart");
var DailyOutputByProdDem = $("#DailyOutputByProdDem").data("kendoChart");
var DailyOutputByProdFFS = $("#DailyOutputByProdFFS").data("kendoChart");
var DailyOutputByDryLineDem = $("#DailyOutputByDryLineDem").data("kendoChart");
var DailyOutputByDryLineFFS = $("#DailyOutputByDryLineFFS").data("kendoChart");
$.ajax({
url: "@Url.Action("Read", "Graphs")",
 
Okay
How do you want to bind the event?
Are you going to chain events, use a button?
 
yes I have few buttons which calls onCriteriaChange
and they use selectedLine variable as parameter
selectedLine changes when I press one of the buttons
 
Okay
 
the GetDailyOutput doesn't have that parameter but it will have
 
3:12 PM
Alright, that's easy enough to add.
The docs for post() are there when you want to do that :)
For now, how exactly will the view be refreshed?
Every time you click the button?
 
yes, the onCriteriaChange() will be called
 
Oh I see
$.post('@Url.Content("~/Graph/_GetDailyOutput")', function( data ) {
    $( "#dvCategoryResults" ).html( data );
});
You should just be able to add that underneath your other AJAX request
$.post() is basically a shorter, nicer syntax for doing AJAX requests than $.ajax()
 
ok I done it, just need to add the parameter to it now
so the header will change to public PartialViewResult GetDailyOutput(string line = "All")
 
Okay
$.post('@Url.Content("~/Graph/_GetDailyOutput")', { line: selectedLine }, function( data ) {
    $( "#dvCategoryResults" ).html( data );
});
That's what it should look like, I think.
 
I got an incident at work may be off for while
 
3:23 PM
Okay. If you could accept and upvote my answer I'd appreciate that :)
 
I will defectively do it, thank you very much
 
No problem
 
4:01 PM
are you still there?
 
4:11 PM
Yeah but for 9 minutes!
didn't see your message sorry
 
ok cool
the post doesn't fire up
 
What error do you get in your console?
On the browser
 
not very experience with that give me second
I don't get any error
 
Keep the console open and make the ajax fire again
 
no error
 
4:15 PM
If there's no error, check the network tab to make sure your controller is returning something
 
ok no it is 404 error
 
Ah
Okay so maybe try $.post('@Url.Action("GetDailyOutput", "Graph")', ....
It just needs to point to the right url,.
You should be able to see what the URL is in your browser, if you open the source and look in your javascript you'll see how ASP.NET is rendering it
I gotta go, good luck!
 
ok thanks
 

last day (14 days later) »