JQuery FileDrop.js How To Read Data Params in Controller? - asp.net-mvc-5

Using ASP.NET MVC 5, I'm having trouble reading the param data I am sending from my filedrop jquery code into my controller.
Here is my .cshtml filedrop code:
And here is my Controller code, showing that param1 is being passed as null:

You can try defining a variable that will hold that the value of attribute. like this
var idValue = $('id').val();
And then pass this variable to the data.
data: { params: idValue }

Related

change the expression in lwc component while iterating

We can use variables in aura components to concatenate some expression, we have to use variable name itself in lwc components, while looping how to change the lwc comp variable in js file.
I tried to access the dom using this.template.querySelector(); but this one is only giving the value if I use a rendered callback.
<template for:each={documentLinks} for:item="item">
//here I need to pass the item.ContentDocument.LatestPublishedVersionId to the end of a URL string
<img src={item.srcUrl} alt="PDF"/>
we can modify the returned data from apex but the data is proxy we cannot modify it.
One of the possible solutions to change the URL on the dom when it loads is to change the returned data from the server. here, In lightning web components the returned data is a proxy object, only readable. so we have to clone it(there are multiple ways to clone it), to make any changes. but here what I did.
therefore, overrides array is going to be the new data.
let overrides = [];
let newData = {
contentDocs: data[i],
srcUrl: '/sfc/servlet.shepherd/version/renditionDownloadrendition=thumb120by90&versionId=' + data[i]['ContentDocument']['LatestPublishedVersionId']
};
makeLoggable(newData);
overrides.push(newData);
function makeLoggable(target) {
return new Proxy(target, {
get(target, property) {
return target[property];
},
set(target, property, value) {
Reflect.set(target, property, value);
},
});
}

Read parameter in ActionFilterAttribute that is not present in action's prototype

I am sending a form using Ajax, it has two inputs.
The receiving action only needs to consume one of the passed values.
An ActionFilterAttribute needs to consume the other argument.
For this reason, I wrote my action as
[AttributeImWriting]
public ContentResult Get(Guid value0) //[...]
but in my action filter when I try to do
context.ActionArguments["value1"]
I get an exception because the argument does not exist.
System.Collections.Generic.KeyNotFoundException: 'The given key 'value1' was not present in the dictionary.'
If I change the action's prototype to
public ContentResult Get(Guid value0, string value1) //[...]
Then I can read value1 from my filterAttribute.
So the question is: In an ActionFilterAttribute, how can I read an argument that was sent by a form, but which is not present in the prototype of the action on which the filter is applied?
I also tried using RouteData.Values but it didn't work any better.
If you are using POST to send values to controller side , in custom ActionFilterAttribute , you can get the parameters from Form property :
var value1 = context.HttpContext.Request.Form["value1"].ToString();
If you are using Get to send values to controller side , you can get the parameters from QueryString property ,then split and get each item:
var querystring = context.HttpContext.Request.QueryString;

DataTables reload table with different pageLength param

Based on this question.
I initialize my datatables.js table with the following code:
var table_entity = $('#myTable').DataTable({
"pageLength":getParameterByName('pageLength'),//getting param from query string
fixedHeader: true,
"ajax": {
"url": myUrl,
"data": function(d) {
d.type = $('#mytype').val();
}
}
});
So I know how to reload my datatable with different ajax params. Now I need to reload it with different pageLength param which does not belong to ajax section and is recorded during datatables init stage. I tried to pass it directly during reloading with the following code:
table_entity.ajax.reload({
"pageLength":77 //some new param different from the initial one
});
But it did not work, the table is reloaded with initial pageLength value. Any ideas how to fix it would be welcome. Thank you.
UPD_1
managed to do that with
1st: complete destruction of a table:
$('#MyTable').DataTable().destroy();
$('#MyTable tbody').empty();//note tbody here
2nd: reinit the table with updated params:
table_data.displayStart = Number(getParameterByName('displayStart'));
table_data.pageLength = Number(getParameterByName('pageLength'));
table_data.iDisplayStart = Number(getParameterByName('displayStart'));
table_data.iDisplayLength = Number(getParameterByName('pageLength'));
$('#MyTable').DataTable(table_data);
Note 2 params - iDisplayStart and iDisplayLength here
Is it possible to do the same without destruction of the table, but during ajax.reload phase? Thank you.
Is it possible to do the same without destruction of the table, but
during ajax.reload phase?
You can hook into the xhr.dt event and update page.len() from there. Example :
$('#example').on('xhr.dt', function(e, settings, json, xhr) {
table.page.len(json.data.length).draw()
})
Will dynamically set the page length to maximum i.e length of data. Demo -> http://jsfiddle.net/d72zbyus/
So you could use table.page.len(77).draw() or whatever. xhr.dt is triggered after each AJAX request.
It is not clear to me where your new pageLength come from exactly. If it is part of the returned JSON (as I suspect) you could do table.page.len(json.pageLength).draw().

Generate Url during runtime from asp.net mvc controller/action

I have such a url:
www.test.com/MyAreaName/MyControllerName/MyAction?key1=value&key2=value
I need a method like:
string generatedUrlWithQueryParams = Url.Action<MyController>(x => x.MyAction(MyViewModel));
I need to call the above method from a .cs class NOT from razor html file.
How can I do that? I heard of asp.net mvc futures but I can not find the appropriate method or namespace to use that method.
Are you looking for something like this:
string url = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
If you have the Request available(it is available in your controller actions), you can use the UrlHelper class.
var urlBuilder = new UrlHelper(Request.RequestContext);
var url = urlBuilder .Action("YourAction", new YourViewModel { Age = 44, Code = "Test"});
or
var url = urlBuilder .Action("YourAction", "YourController",
new YourViewModel { Age = 44, Code = "Test"});
Assuming YourViewModel has Age and Code property and you need those as the route values of the generated url.
If you are invoking this code from another class, you may pass the RequestContext to that from your controller/action.

add/read parameters to/from the url

If I add parameters to the url in the Objective-C code, is it possible to read it from the client?
Example:
- (NSURL *)serverURL {
return [NSURL URLWithString:#"http://rap.eclipsesource.com/demo?parametername=value"];
}
In the Client-JavaCode I can get the value of the parameter like this:
String parameter = RWT.getRequest().getParameter("parametername");
If I access the "app" with the browser I get a value for the parameter. If I access the app with the TabrisClient the value is null.
Is there a way to get the value also in the TabrisClient?
Update:
The server does not directly extract the query string from the request URL, but from the first JSON message received from the client. The web client provides the parameter queryString in the head part of the first UI request. Example:
{
"head": {
"queryString": "foo=23&bar=42",
"requestCounter": ...
},
"operations": [
...
]
}
You would have to fake this behavior in your Tabris client. I'd suggest that you file an issue against Tabris to provide API to set startup parameters.
Original answer:
If you're going to hard-code the parameter in the tabris client anyway, you could set the variable based on the connected client:
parameter = (RWT.getClient() instanceof WebClient)
? RWT.getRequest.getParameter("parametername")
: "tabris-value";
BTW, access to request parameters is going to change in RAP 3.0. Instead of RWT.getRequest().getParameter(), a ClientService will provide the parameters.

Resources