nxuybcbkbcbggkcwcbregrwyywbrgewbyrewyreyrwebyrwrwe
test
Browser.ExecuteScriptAsync();
Sends javascript to be executed and expects nothing in return, so trying to assign 'nothing' (ie void) to an HtmlElement variable is a no go.
If you are looking to send the page a bit of javascript, and use what is sent back, you need to use EvaluateScriptAsync()
This will return a Task<JavascriptResponse> which will still not work if you are trying to assign it to Size. Here is the bad news: JavascriptResponse can only be basic data types (int, bool, string, etc.). As per their documentation:
Only trivial values can be returned (like int, bool, string etc) - not
a complex (user-defined) type which you have defined yourself. This is
because there is no (easy) way to expose a random Javascript object to
the .NET world, at least not today. However, one possible technique is
to turn the Javascript object you wish to return to your .NET code
into a JSON string with the Javascript JSON.toStringify() method and
return that string to your .NET code. Then you can decode that string
into a .NET object with something like JSON.net. See this MSDN link
for more information.
(https://msdn.microsoft.com/en-us/library/ie/cc836459(v=vs.94).aspx)
For more info see:
https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions
Related
I have a scripting functoid with the following code:
public string MyConcat(string product)
{
string retStr= "01";
product = product.ToUpper();
if(product.Contains("CONDITION")){
retStr= "02";
}
return retStr;
}
This works perfect when I run it in LinqPad, but when I test the map it returns the product string instead of the retStr, which I find really weird. Any help is much appreciated.
You probably have another Scripting functoid that has the same signature, i.e. is called MyConcat, returns a string, has a single string input. In that case it will execute the first version created with the input linked to it.
Please make sure you give your function names a unique and descriptive name to avoid this.
If you do need to use the same function multiple times in your map, this feature of it re-using the the function is quite useful, but I usually make sure to add a comment to all the subsequent copies stating that only the first version has the code.
I have a pretty basic, but probably complicated question.
I am using ReactJS.net to render react components server side. I have a typeahead component which I use multiple times throughout my site. One of the properties it expects is a javascript filter function.
I don't want to have to create a seperate component for each instance of the typeahead, but would like to pass in a javascript function as a property so that I can reuse the component throughout the site.
For example, to render a component on the server I would do the following. The second parameter is the properties argment
#Html.React("Components.WorkSiteTypeahead", new { filterFn = model.SomeFunction })
Now as ReactJS.net expects native c# objects (string, array, list, etc), I don't see any straight forward way to pass in a Javascript function. Any ideas on how would I go about telling my MVC5 view to render my function not as a string? My first instinct is that there might be some sort of Javascript Raw type I am not aware of, but haven't been able to find it.
As I suspected, at least one way to go about this is to use Newtonsoft's JRAW Type.
#Html.React("Components.WorkSiteTypeahead", new { filterFn = JRaw("function(){//do stuff } "})
I'm going from the ASP.NET Web API template to get rolling on building an API. I need to figure out a way to take the GET parameters and apply them to my code so for example:
I would like to query my DB for names like "TOYOTA" by entering:
http://localhost:64360/api/values?name=TOYOTA
For now, here's the code that I have to work with:
' GET api/values
Public Function GetValues() As IEnumerable(Of String)
Return New String() {"value1"}
End Function
For the moment, this URI will return a single JSON object that just says:
"value"
But for the sake of figuring out how to input GET parameters into the VB code above,
How could I make the block of code above return whatever is inputed as ?name=AUDI so that instead of just getting "value" I would get AUDI, TOYOTA, or whatever the GET parameter with name is?
The WebAPI paramenters use almost the same approach as MVC,
So just change input parameters like this:
Public Function GetValues(name As String) As IEnumerable(Of String)
Take a look at http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api. It doesn't look to me as though you are really using Web API, but instead are trying to build, by hand, a lot of the stuff that Web API provides. In particular, look at the model binders as those will really give you a lot of flexibility, especially in terms of flexibility of input formats (i.e. automatic acceptance and decoding of XML, JSON or GET parameters).
You should be naming actions on your controller that match the verbs, e.g. GET, POST, etc.
I think you need to do some more research into the Web API.
There are some posts on this, but not an answer to this specific question.
The server is returning this: "/Date(1304146800000)/"
I would like to not change the server-side code at all and instead parse the date that is included in the .Net generated JSON object. This doesn't seem that hard because it looks like it is almost there. Yet there doesn't seem to be a quick fix, at least in these forums.
From previous posts it sounds like this can be done using REGEX but REGEX and I are old enemies that coldly stare at each other across the bar.
Is this the only way? If so, can someone point me to a REGEX reference that is appropriate to this task?
Regards,
Guido
The link from Robert is good, but we should strive to answer the question here, not to just post links.
Here's a quick function that does what you need. http://jsfiddle.net/Aaa6r/
function deserializeDotNetDate(dateStr) {
var matches = /\/Date\((\d*)\)\//.exec(dateStr);
if(!matches) {
return null;
}
return new Date( parseInt( matches[1] ) );
}
deserializeDotNetDate("/Date(1304146800000)/");
Since you're using jQuery I've extended its $.parseJSON() functionality so it's able to do this conversion for you automatically and transparently.
It doesn't convert only .net dates but ISO dates as well. ISO dates are supported by native JSON converters in all major browsers but they work only one way because JSON spec doesn't support date data type.
Read all the details (don't want to copy blog post content here because it would be too much) in my blog post and get the code as well. The idea is still the same: change jQuery's default $.parseJSON() behaviour so it can detect .Net and ISO dates and converts them automatically when parsing JSON data. This way you don't have to traverse your parsed objects and convert dates manually.
How it's used?
$.parseJSON(yourJSONstring, true);
See the additional variable? This makes sure that all your existing code works as expected without any change. But if you do provide the additional parameter and set it to true it will detect dates and convert them accordingly.
Why is this solution better than manual conversion? (suggested by Juan)
Because you lower the risk of human factor of forgetting to convert some variable in your object tree (objects can be deep and wide)
Because your code is in development and if you change some server-side part that returns JSON to the client (rename variables, add new ones, remove existing etc.), you have to think of these manual conversions on the client side as well. If you do it automatically you don't have to think (or do anything) about it.
Two top reasons from the top of my head.
When overriding jQuery functionality feels wrong
When you don't want to actually override existing $.parseJSON() functionality you can minimally change the code and rename the extension to $.parseJSONwithdates() and then always use your own function when parsing JSON. But you may have a problem when you set your Ajax calls to dataType: "json" which automatically calls the original parser. If you use this setting you will have to override jQuery's existing functionality.
The good thing is also that you don't change the original jQuery library code file. You put this extension in a separate file and use it at your own will. Some pages may use it, others may not. But it's wise to use it everywhere otherwise you have the same problem of human factor with forgetting to include the extension. Just include your extension in some global Javascript file (or master page/template) you may be using.
the application is very large so giving a brief back ground and the problem
when the user logs in, a button is displayed having the text of the function he is allowed to call.
the function he is allowed is mapped in the database table
its made sure that the name of the actual function is same to the ones used in the db.
problem
the name is extracted, and stored as text field of button and also in a string variable.
now how am i supposed to call this function using the string variable which has the name stored in it!
like we type
name-of-function();
but here i dont know the name, the string at run time does so i cant write like
string()!!?
You will need to use reflection to do this. Here is a rough sketch of what you need to do:
// Get the Type on which your method resides:
Type t = typeof(SomeType);
// Get the method
MethodInfo m = t.GetMethod("methodNameFromDb");
// Invoke dynamically
m.Invoke(instance, null);
Depending on your actual needs you will have to modify this a little - lookup the used methods and types on MSDN: MethodInfo, Invoke
Well, no matter what you do, there is going to have to be some kind of mapping done between a database "function" and your "real" function. You can probably use Reflection using your Types and MethodInfo.
However, this sounds like a maintenance nightmare. It also sounds like you are reinventing user roles or the like. I would be very cautious about going down this path - I think it will be much more complex and problematic than you think.