Concatenate string in Asp Mvc - string

I am using ajax jquery for return a string , i have a entangle , it is Concatenate string
I want concatenate :
string str = "";
str += "<td>"+"<%= Html.ActionLink('Edit', 'ProcessUpdate/' + s.ProductId, 'Stationery')%>"+" </td>";
but when i run application , this is result :
I want to run the program the following results
Edit
thank for all !

It looks your issue is the parameters you are passing to Html.ActionLink(). Your question has been answered
here. The "/" character in your second parameter is not valid since this parameter is the action name in MVC2+ or the controller name in MVC1.
Assuming Stationery is the controller and ProcessUpdate is the action on the controller, your code should look like this:
Html.ActionLink("Edit", "ProcessUpdate", "Stationery" new { Id = s.ProductId }, new { } )
And here is the signature for the action
public ActionResult ProcessUpdate(string id)
{
// Do something
}
Note the last parameter is for Html Attributes and is required for this overload of Html.ActionLink() to work properly.

Related

How to map undefined amount of path parameters to request parameters in Ocpsoft Rewrite?

Currently I´m trying the following JSF - Lib:
https://www.ocpsoft.org/rewrite/examples/
I have the following issue:
I have a page:
/page.jsf
In my page I have more then only one parameter.
E.g. I have:
- parameter1
- parameter2
String parameter1 = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("parameter1");
String parameter2 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
.get("parameter2");
Currently I understood I can add this in my UrlConfigProvider class:
.addRule(Join.path("/page/{parameter1}").to("/portal/mypage.jsf")
.withInboundCorrection())
This is working for one parameter.
But how can I do this for multiple parameter, so the URL is then:
/page/{parameter1}/{parameter2}
....
Any ideas?
The rewrite API doesn't bring a native solution for this problem.
Kick-Off Example
.addRule()
.when(/* your condition */)
.perform(new HttpOperation() {
#Override
public void performHttp(HttpServletRewrite httpServletRewrite, EvaluationContext evaluationContext) {
// this is the default wrapper
HttpRewriteWrappedRequest request = ((HttpRewriteWrappedRequest) httpServletRewrite.getRequest());
// get the uri (example: '/index/p1/p2')
String uri = httpServletRewrite.getRequest().getRequestURI();
// split by slash
String[] split = uri.split("/");
// this is example specific
// split value 0 is empty and split value 1 is the page (e.g. 'index')
// for every folder increment the index
// for '/pages/index' the start index should 3
for (int i = 2; i < split.length; i++) {
String s = split[i];
// the request parameter is by default an immutable map
// but this returns a modifiable
request.getModifiableParameters().put("prefix" + (i - 1), new String[]{s});
}
}
});
Explanation
The only important piece is the HttpOperation. By default the ServletRequest is wrapped in a HttpRewriteWrappedRequest.
The default HttpServletRequest doesn't allow to change the parameters once they were initialized. The method getParameterMap() returns an immutable map.
getParameterMap() of the HttpRewriteWrappedRequest also returns an immutable map. But getModifiableMap() returns obviously a modifiable map.
The rest should be self-explanatory.
See Also
Ocpsoft: How to modify parameters
Modify request parameter with servlet filter

Grails search/filter multiple parameters - controller logic

Using Grails (or hibernate), I was wanting to know if there is a specific design pattern or method we should be using when implementing a SEARCH of our domain.
For example, on my website, I want to be able to filter(or search) by multiple properties in the domain.
EG: For I have a page which displays a list of HOTELS. When I submit a search form, or if a user clicks "filter by name='blah'", when I enter the controller I get the following:
Domain
String name
String location
Controller
if(params.name && params.reference) {
// Find name/reference
} else if(params.name) {
// Find name
} else if(params.reference) {
// Find reference
} else {
// Find all
}
As you can understand, if there are more properties in the domain to search/filter, the longer the controller gets.
Any help. Please note, I do not want to use the 'searchable' plugin, as this is too complex for my needs.
I would embed these in a named query in the Domain class itself. For example:
Class Hotel {
String name
String city
String country
boolean isNice
static namedQueries = {
customSearch { p ->
if (p?.name) eq('name', p.name)
if (p?.city) eq('name', p.city)
if (p?.country) eq('name', p.country)
if (p?.isNice != null) eq('isNice', p.isNice)
}
}
}
Then later in a controller somewhere ...
def results = Hotel.customSearch(params)
Of course this is a very simple example, but you can expand on it using the same named query or even adding others and chaining them together.

Kohana 3.3 ORM Validation - unique value not working when value is empty

In a Model_Page class, extending the Kohana ORM class, I have this rules definition :
public function rules() {
return array(
'url' => array(
array('Model_Page::unique_url', array($this)),
),
);
}
To simplify here, I will just return false from this function, so it should never validate when I try to save/update a page :
public static function unique_url($page) {
return false;
}
This works as expected, if the value for url is not NULL or not an empty string.
But if I already have a page with an empty url, and that I try to add a new page with an empty url, the unique_url function is ignored, even when forcing a return false.
This could be a bug, but maybe I missed something...? In the Kohana docs, for the unique example, they use a username as an example, but the username also has a not_empty rule, which does not apply here.
Any help/suggestion appreciated!
I believe the rule is applied once you set the value, not when you're saving it.
I had a similar issue - the filter wasn't working if I didn't assign any value to the field. I've written my own save method:
public function save(Validation $validation = NULL)
{
if (!$this->loaded())
{
$this->ordering = 0;
}
return parent::save($validation);
}
this way the ordering would always be assigned for newly created objects and my filter would work.
And that's how I built another model. It's a company model that has a unique company name. Rules for the field are defined like this:
'name' => array(
array('not_empty'),
array('max_length', array(':value', 255)),
array(array($this, 'unique_name'))
)
And I have a method:
public function unique_name($value)
{
$exists = (bool) DB::select(array(DB::expr('COUNT(*)'), 'total_count'))
->from($this->_table_name)
->where('name', '=', $value)
->where($this->_primary_key, '!=', $this->pk())
->execute($this->_db)
->get('total_count');
return !$exists;
}
It basically checks if there are any other companies with the same name as the current one. Maybe this will give you the idea of what could be wrong with your solution.

ServiceStack - Redirecting at root based on query params [duplicate]

This question already has answers here:
Create route for root path, '/', with ServiceStack
(3 answers)
Closed 3 years ago.
I've got a Fallback DTO that looks like the following:
[FallbackRoute("/{Path*}")]
public class Fallback
{
public string Path { get; set; }
}
Now, in my Service I would like to redirect to an HTML5 compliant URL, and this is what I've tried:
public object Get(Fallback fallback)
{
return this.Redirect("/#!/" + fallback.Path);
}
It is working all fine and dandy, except for the fact that query parameters are not passed along with the path. Using Request.QueryString does not work as no matter what I do it is empty. Here's what my current (non-working) solution looks like:
public object Get(Fallback fallback)
{
StringBuilder sb = new StringBuilder("?");
foreach (KeyValuePair<string, string> item in Request.QueryString)
{
sb.Append(item.Key).Append("=").Append(item.Value).Append("&");
}
var s = "/#!/" + fallback.Path + sb.ToString();
return this.Redirect(s);
}
TL;DR: I want to pass on query strings along with fallback path.
EDIT: It turns out I had two problems; now going to mysite.com/url/that/does/not/exist?random=param correctly redirects the request to mysite.com/#!/url/that/does/not/exist?random=param& after I changed the above loop to:
foreach (string key in Request.QueryString)
{
sb.Append(key).Append("=").Append(Request.QueryString[key]).Append("&");
}
But the fallback is still not being called at root, meaning mysite.com/?random=param won't trigger anything.
In essence, what I want to do is to have ServiceStack look for query strings at root, e.g., mysite.com/?key=value, apply some logic and then fire off a redirect. The purpose of this is in order for crawler bots to be able to query the site with a _escaped_fragment_ parameter and then be presented with an HTML snapshot prepared by a server. This is in order for the bots to be able to index single-page applications (more on this).
I'm thinking perhaps the FallbackRoute function won't cover this and I need to resort to overriding the CatchAllHandler.
I managed to find a solution thanks to this answer.
First create an EndpointHostConfig object in your AppHost:
var config = new EndpointHostConfig
{
...
};
Then, add a RawHttpHandler:
config.RawHttpHandlers.Add(r =>
{
var crawl = r.QueryString["_escaped_fragment_"];
if (crawl != null)
{
HttpContext.Current.RewritePath("/location_of_snapshots/" + crawl);
}
return null;
});
Going to mysite.com/?_escaped_fragment_=home?key=value will fire off a redirection to mysite.com/location_of_snapshots/home?key=value, which should satisfy the AJAX crawling bots.
N.B. It's possible some logic needs to be applied to the redirection to ensure that there won't be double forward slashes. I have yet to test that.

Missing FlashVars in Flash Professional CS5 and swfobject?

I have a Flash Professional CS5 movie which I'm trying to pass a parameter with swfobject. The problem is that movieclip's flashvar variables (under loaderInfo.parameters) is null.
Here is the swfobject code:
function loadSetupBar(connectId)
{
// add the setup bar to the DOM using swfobject
swfobject.embedSWF("{{setupBarSwf}}",
"swf-setup-bar",
{{gameWidth}}, $("#top-bar").height(),
"10.0.0", "{{installSwf}}",
{connectionId : connectId },
{
allowFullScreen : true,
wmode : 'opaque',
allowscriptaccess: "always"
},
{name:"swf-setup-bar"}
);
}
According to the swfobject documentation, everything seems to be ok.
Here's the corresponding code inside the FLA (A MovieClip with its own AS3 class):
var params : Object = root.loaderInfo.parameters;
var connectionId : String = params.connectionId;
if ( !params.hasOwnProperty('connectionId') )
// this line is always printed.
trace("[SetupBar-Error] loaderInfo parameters missing property 'connectionId'")
I'm not sure about what else to do.
Thanks.
EDIT: Here is a list of things I've tried that have failed:
casted root.loaderInfo to class LoaderInfo ( i.e. LoaderInfo(this.root.loaderInfo) )
passing a String literal in swfobject.embedSWF instead of param connectId
(i.e. {connectionID : 'myTestValue'})
There's a problem with the TLF TEXT control, when you add it to the stage the flashvars begins not working . just don't use it and your flashvars will work fine . i've faced the same problem and i got it solved by not using TLF TEXT control.
I hope i helped .
Best Regards
Try this:
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var connectionID:String = params.connectionId;

Resources