Pass more than one parameter can be used in Html.Action - html

how to pass more than one parameter using an Html.Action.
# Html.Action("StringName","ActionName","Controller",new{id=param1,name=param2})
Please let me know is this correct format.

Edit: This answer is for ActionLink. You can still use the parameters to invoke actions (which are invoked directly when you use Html.Action)
You can just pass them (as you did in the example). All parameters which are not found in the route are used as query string parameters.
You can catch all of them in another action.
Note that all values should be correct C# declarations, so to pass the second parameter as a string you need to use double quotes (as in regular C# code):
#Html.Action("StringName","ActionName","Controller",new{id=param1,name="param2"})

Related

I am trying to add a username and string combined to a variable in Jmeter [duplicate]

I have a requirement to use randome url from a url list I extract from a json response.
Say I extract them in this mannser
imageUrls_1=https://blah01.com
imageUrls_2=https://blah02.com
imageUrls_3=https://blah03.com
imageUrls_4=https://blah04.com
imageURLs_matchNr=4
In a following JSSR223 sampler I was able to generate a variable called "url" with one of the url names selected randomely
("imageUrls_1","imageUrls_2",etc)
I was thinking to use them in my HTTP request to get the correcponding url as follows. ${${url}}. But soon found out its not giving me anything other than "${${url}}" :(.
JMeter Is it possible to place a varibale inside a varible name?
Basically I need to use one of the extracted urls randomely in my HTTP request.
The easiest way is going for __V() and __Random() functions combination like:
${__V(imageUrls_${__Random(1,${imageURLs_matchNr},)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Use __V function
${__V(url)}
The V (variable) function returns the result of evaluating a variable name expression.

how to check null /empty or value based on response from previous Sampler in Jmeter?

I have extracted the value from Json response for one of the Key. It has two possible values as either
Key=[] or
Key=[{"combination":[{"code":"size","value":"Small"}]},{"combination":
[{"code":"size","value":"Medium"}]}]
I need to check whether Key is [] or it has some values. Could you please help me what is wrong with below implementation:
if ("${Key}"=="[]") {
vars.put('size', 'empty')
} else {
vars.put('size', 'notempty')
}
My Switch controller is not navigating to Else Part based on above implementation . Help is useful!
Don't ever inline JMeter Functions or Variables into script body as they may resolve into something which will cause compilation failure or unexpected behaviour. Either use "Parameters" section like:
or use vars.get('Key') statement instead.
Don't compare string literals using ==, go for .equals() method instead
See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests
If you have an already extracted value Key and you are using an if controller with the default JavaScript you can do the following in the condition field:
"${Key}".length > 0
The "${Key}" is evaluating to your JavaScript object which is an array. You can check the length of the array to see if there are objects in it.

Using jmeter variable in if controller

I want to use the jmeter if controller and use a jmeter variable which I get while processing the previous response.
I have two services search and register. The logic I want to use is hit the search service, if I get a good response (i.e. the search exists) no need to register. If the search is empty hit register service and check the search service again.
So I have a Simple controller. Under simple controller I have search service with BSF assertion. Next thing under simple controller is the if controller (with register service) for which I need a variable (say ${found} )
I will be creating the variable in bsf assertion as
import groovy.json.*
def slurper = new JsonSlurper()
def result = slurper.parseText(prev.getResponseDataAsString())
if (result.id != null ) {
def found = 0 // can be text logical or any other type ..
}
Question: Can I use the variable ${found} created in the bsf assertion search service as a condition for If controller ? Will it be available beyond the service. Will it be better to have it as user defined variable ?
Depending on found variable type it can be:
vars.put("found", found); - for String
vars.put("found", String.valueOf(found)); - for chars, integers, floats, doubles, booleans, etc.
vars.putObject("found", found) - for anything which cannot be cast to a String
props.put(found, found); - for any Object types. Opposite to JMeter Variables JMeter Properties have "global" scope and Variables visibility is limited to the current thread group only so if you need to pass this value to another Thread Group you need to use properties.
Be careful while setting conditions in the If Controller as in case of string literals you'll need to put both variable and value in quotation marks like:
"${found}"=="someid"
See How to use JMeter's 'IF' Controller and get Pie. guide for more details.
By the way, there is a couple of test elements available via JMeter Plugins which are designed to work with JSON data so you won't have to use BSF scripting:
JSON Path Extractor - to perform correlation on JSON data
JSON Path Assertion - to use assertions on response
yes the variable "found" can be used. But you need to add the following at the end of your code
vars.put("found",found);
Hope this will help.

Golang dynamic number of bind variables

I've been working with MyMySQL and currently have written an API call that takes a variable number of parameters and generates a search query. I have been trying to bind the passed in parameters to protect against SQL injection, however I cannot seem to figure out how to handle a variable amount of parameters. The Bind function signature looks like:
Bind(params ...interface{})
Although I guessed both solutions wouldn't work, I tried binding each parameter one at a time in a loop, and then also tried passing in a []interface{} containing all of the parameter values.
Is there anyway to handle this solution? Struct binding wont work since I could have multiple values per each field. For instance, I could have 1 or 10 company IDs passed back to me.
Your second attempt was close to success. Build a, say var foo []interface{} containing all arguments and pass it as
Bind(foo...)
See also Passing arguments to ... parameters

passing get parameters in a get parameter

I don't know if this is possible, and I'm sure i'm not calling it the right thing, but how can I pass a url with get parameter inside a get parameter itself? For example, I want to pass http://example.com/return/?somevars=anothervar as a value for the "return" parameter as show below:
http://example.com/?param1=4&return=http://example.com/return/?somevars=anothervar
URL-encode the inner parameter. How you do this depends on the language you're using, or if you're doing it by hand, so in the absence of information I'll just say that ? is %3F, & is %26 and # is %23 - those are the only ones that are "required" for the browser to understand what you're doing.