Hi I am using the AutoCompleteExtender ajax control. I am getting the list of strings in LIST collection. I want to populate only those strings, which user typing as prefix text. how to do this. I am following the example given in ajax toolkit.let say user typing "ca" then if list contain the list like,
'cat', 'dog', donkey', 'mouse','cart'....etc.
Then it should populate only 'cat' and cart'.
How to achieve this?
In the example there's a description of the properties. Quote:
ServiceMethod - The web service method to be called. The signature of
this method must match the following:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count) { ... }
Note that you can replace
"GetCompletionList" with a name of
your choice, but the return type and
parameter name and type must exactly
match, including case.
ServicePath - The path to the web service that the extender will
pull the word\sentence completions
from. If this is not provided, the
service method should be a page
method.
So you need write a web service which will contain a method returning the list of suggestions based on the user input.
Related
I'm new to Umbraco, so this may not even be feasible. I've created my own Datatype using Archetype and want to be able to get an instance of that type on the page by type, not alias.
I know that I can do the following:
model.Content.GetPropertyValue("myAlias")
But I want to know if it's feasible to get the property by the type. Something along the lines of:
model.Content.GetPropertiesByType("TypeName")
which would return a list of controls on the page of that type?
Is this feasible?
It's possible, but not exactly straight forward.
Take a look at the available Umbraco Data Services - you'll need to retrieve the DataTypeDefinitions from the DataTypeService and retrieve the ContentType for the Model's IPublishedContent using the ContentTypeService.
Once you have these, you can match up the PropertyTypes on the ContentType with the retrieved DataTypeDefionitions based on the PropertyType's DataTypeDefinitionId.
The PropertyTypes have an Alias property which will match up with the Property Aliases on the Content itself.
You can use the content service if you get the id of the datatype you trying to find the multiples of from the url when you edit/create the datatype.
#foreach (var p in ApplicationContext.Current.Services.ContentService.GetById(Model.Content.Id).PropertyTypes.Where(p => p.DataTypeDefinitionId == -89))
{
<p>#p.DataTypeDefinitionId</p>
}
I'm developing a asp.net mvc website for an intranet system. In this system, I have several pages with grids. I am using the Grid.MVC extension to build these grids.
Grid.MVC supports the filter function based on GET parameters. For example, if I want to filter the column name where name = "michael", I need to pass a url GET parameter like this: ?grid-filter=name__1__michael;. The number 1 refers to the type of filter, equals in this case.
It supports multiple filters too. To use this, I need to pass the grid-filter parameter multiple times, like ?grid-filter=name__1__michael;grid-filter=age__1__21. I don't know how to pass the grid filter multiple times when I am returning a redirectresult from an action. Does anybody know how to do this?
Having searched awhile to solve the problem myself, plus if I understand you correctly, I think what you want to do is to PASS (multiple-times) SAME PARAMETER to controller.
Definitely as your questions states, it can help to redirect to the appropriate page while retaining all the data.
Here is a simple MVC example with Controller and View.
public ActionResult(List<string> gridfilter, List<string> param2)
{
ViewBag.gridfilter = gridfilter;
ViewBag.param2= param2;
}
Then, to display the values in View, you can do like this on the View Page:
#foreach(var grids in ViewBag.gridfilter)
{
<p>#grids</> //displays current value
}
#foreach(var param in ViewBag.param2)
{
<p>#param</> //displays param 2 value
}
In your Url, you can then post as many value of your parameters as you want.
Example:http://example.com?gridfilter=anystring&gridfilter=anystringagain¶m2=anystring
I have an MVC Web API Get method that accepts a List<string> as a parameter. I'm trying to access this method using simply the browser bar. How is this done? Using ../APIName?parameter1=value1¶meter2=value2&... passes a single parameter between two ampersands as opposed to a list.
Make sure your parameter of your action method is marked as [FromUri]. By default the value is expected to be passed from the body of the request since it is a complex type.
public List<string> Get([FromUri] List<string> parameter)
{...}
The query string parameter should be of this format .../APIName?parameter[]=value1¶meter[]=value2&....
Hope this helps.
I have a Person class with two properties: name and address. I want to build a GSP page which allows for 10 users to be created at one time. This is how I'm implementing it and was wondering if there is a better way:
First, make 20 text boxes in the GSP page - 10 with someperson.name and 10 with someperson.address field names (make these in a loop or code them all individually, doesn't matter).
Second, process the submitted data in the controller. The someperson object has the submitted data, but in a not-so-nice structure ([name: ['Bob', 'John'], address: ['Address 1', 'Address 2']]), so I call transpose() on this to be able to access name, address pairs.
Then, build a list of Person objects using the pairs obtained from the previous step and validate/save them.
Finally, if validation fails (name cannot be null) then do something... don't know what yet! I'm thinking of passing the collection of Person objects to the GSP where they are iterated using a loop and if hasErrors then show them... Don't know how to highlight the fields which failed validation...
So, is there a better way (I should probably ask WHAT IS the better way)?
You should use Grails' data-binding support by declaring a command object like this
class PersonCommand {
List<Person> people = []
}
If you construct your form so that the request parameters are named like this:
person[0].name=bob
person[0].address=england
person[1].name=john
person[1].address=ireland
The data will be automatically bound to the personCommand argument of this controller action
class MyController {
def savePeople = {PersonCommand personCommand->
}
}
If you call personCommand.validate() it might in turn call validate() on each Person in people (I'm not sure). If it doesn't you can do this yourself by calling
boolean allPersonsValid = personCommand.people.every {it.validate()}
At this point you'll know whether all Person instances are valid. If they are not, you should pass the PersonCommand back to the GSP and you can use the Grails tags:
<g:eachError>
<g:hasErrors>
<g:renderErrors>
to highlight the fields in errors. If you're not exactly sure how to use these tags to do the highlight, I suggest you run grails generate-all for a domain class and look at the GSP code it generates.
Short: how does modelbinding pass objects from view to controller?
Long:
First, based on the parameters given by the user through a search form, some objects are retrieved from the database.
These objects are given meta data that are visible(but not defining) to the customer (e.g: naming and pricing of the objects differ from region to region).
Later on in the site, the user can click links that should show details of these objects.
Because these meta data are important for displaying, but not defining, I need to get the previously altered object back in the controller.
When I use the default asp.net mvc modelbinding, the .ToString() method is used. This off course doesn't return a relevant string for recreating the complete object.
I would have figured the ISerializable interface would be involved, but this is not so.
How should I go about to get the desired effect? I can't imagine I'm the first one to be faced with this question, so I guess I'm missing something somewhere...
The default model binding takes form parameters by name and matches them up with the properties of the type specified in the argument list. For example, your model has properties "Price" and "Name", then the form would need to contain inputs with ids/names "Price" and "Name" (I suspect it does a case insensitive match). The binder uses reflection to convert the form values associated with these keys into the appropriate type and assigns it to the properties of a newly created object of the type specified by the parameter (again derived by reflection).
You can actually look at (and download) the source for this at http://www.codeplex.com/aspnet, although you'll have to drill down into the MVC source from there. I'd give a link to the DefaultModelBinder source, but the way they are constructed, I believe the link changes as revisions are introduced.
So, to answer your question, you need to have parameters (could be hidden) on your form that correspond to the properties of the object that you want to recreate. When you POST the form (in the view) to the controller, the binder should reconstitute an object of the specified type using the form parameters. If you need to do translation from the values in the form parameter to the object properties, you'll probably need to implement your own custom model binder.
[EDIT] In response to your second post:
Let's say that we want to have a link back to an action that uses a customized object. We can store the customized object in TempData (or the Session if we need it to last more through more than one postback) with a particular key. We can then construct the action link and provide the key of the object as value to the ActionLink in an anonymous class. This will pass back the key as a Request parameter. In our action we can use the key from this parameter to retrieve the object from TempData.
<%= Html.ActionLink( ViewData["CustomObject1",
"Select",
new { TempDataKey = ViewData["CustomObject1_Key"] }
) %>
public ActionResult Select()
{
Entity custObj = null;
string objKey = Request.Params["TempDataKey"];
if (!string.IsNullOrEmpty(objKey))
{
custObj = (Entity)TempData[objKey];
}
... continue processing
}
#tvanfosson
Thanks for your explanation, but what about links? (no forms involved)
Currently the Html.ActionLink(c=>c.Action(parameter), "label") takes objects as parameter. These have to be translated into URL parts. For this, MVC ALWAYS goes to the .ToString() method. I don't want to serialize my object in the ToString method.
Shouldn't I be able to somehow help the framework serialize my object? Say through the ISerialize interface or something?