I can call the controller but the argument (string) is always null.
All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address, well I can't name my controller parameter like that.
So how do I get around this? There must be a way to specify the controllers parameter name in the remote() attribute?
It cannot be done using the default RemoteAttribute. This is a link to an example I posted of a reusable remote validation attribute, where you can specify the name of the controller, action and the name of the variable used to pass the value to the action.
Related
How to access the parameter #{...} in Process configuration field if its name needs to be changed dynamically (for example, the name of this parameter is contained in some FlowFile attribute OR the name generating using expression language).
Illustrative example – for the LogMessage process, I have prepared several parameters in (msg1, msg2, msg3 etc.) that I would like to output depending on the attribute numofmessage
You can do it using evaluateELString()
${literal('{dynamic_${name}}'):prepend('#'):evaluateELString()}
Currently you cannot use EL inside of a parameter reference. If you put something like #{${abc}} it will look for a parameter named ${abc} and won't find one so it will be invalid.
You can only do the reverse, use parameter inside of EL, for example ${ #{abc}:replace('xxx', 'zzz') }.
In general, parameters are meant to be a better version/replacement for the existing variables functionality, but in this case variables may work better for you since variables are referenced through EL.
I have such requests:
/api/roove?request=wager
The request parameter value changes each time.
I have 5 different actions that are determined by that parameter value.
I need to route based on that value.
How can that be achieved.
I want to be able to use this:
[Route("api/roove?request=wager")]
on every action. But an error is thrown if I use symbols like '?'.
I dont want to use a custom parameter value.
How to pass an extra parameter through a Get method of webapi because when i pass
GetALL(int page,int limit,int start) it works fine but when in passed one more parameters that is optional and may be null it throws error.
GetAll(int page,int limit,int start,string ? search)
What is the best way to make it working
In Web API optional parameters are those which can be nulled.
If you have type values like int or DateTime, you need to make them nullableby using the ? syntax.
But when they're classes instead of value type, they are directly convertible to null, so you don't need to, and can not, mark them as nullable. SO, your method signature must be simply this:
GetAll(int page,int limit,int start,string search)
If you wanted page, limit or start to be nullable, you should declare them as int?. So, int he signature above this 3 parameters are compulsory, and the last one optional.
EDIT, for OP comment
When you use the default routing for Web API the only way to choose the right method is by parameter matching, i.e. the parameters in the request must match the parameters in the action including the optional parameters. So, there are two ways to make it work:
post the optional parameters as empty parameters. For your case, provided you're using the query string, include a &search= in the URL
modify the routes, so that the parameters are provided as route parameters, and define the search parameter as optional
You can also completely modify the web API routing by including the action in the route. In that case, you have to specify the action in the URLs to invoke the action, but the method can be chosen by action name (given by method name or Action attribute), and not by parameter matching. In that case you don't need to provide the optional parameters. It will work like MVC routing.
In my view I create links via:
URL::action('NotSureWhatController#getIndex', 'id') }}
My view is a template that is used by a variety of different controllers, what's the best way to change the name of the controller in the action?
The only thing I can think of is setting a var in the controller and passing it through.
Is there a better way? Or a way to get the controller name?
I can't use 'as' in the route to name the controller either (as this is used for something else) so this won't work:
Route::currentRouteName()
Option 1
You should create the URL directly in the controller, then pass it as a variable to the view. The view will just print the url.
Option 2
You pass the name of the controller as a variable to the view (always from the controller), then you use the escape values of the blade templating to print it inside your function to generate URLs.
Option 3
Using the REQUEST class to get information about the page.
I've read the URI parameters user guide and still have a question:
http://codeigniter.com/user_guide/general/routing.html
With the following:
{http://myapp/locations/1} I get a 404 error...
{http://myapp/locations} appropriately executes the index() function in the Main controller
{http://myapp/locations/main/locations/1} works, and the value is passed properly to index($var)
I do have other functions in Main.
How is it possible to get the first line to work in order to clean URL's?
Thanks in advance,
Alan
CodeIgniter reads an url as domain/controller_name/method-name/method_parameters and in your first url here http://myapp/locations/1 the first portion (myapp) is your domain name, second (locations) is your controller name and the third portion should be controller's method name and in this case you've passed 1 and obviously there's no such a method name, so it's showing error.
if you pass domain/controller_name like you did here in this url http://myapp/locations, then CodeIgniter reads the first portion as the domain_name and the second portion as controller_name and when there is no third portion in the url then CodeIgniter calls the index method/function by default, so your second url is working.
In your last url you have http://myapp/locations/main/locations/1 and it's been read as
myapp-domain name
locations-controller name
main-method/function name
and rest of all are passed as main controller's arguments. So remember that, the third part of an url is method/function name and if third part is not given then CodeIgniter calls the index method by default and in that case you have to declare a default index method/function in that controller, otherwise an error will be occured.