With the UIHint you can also store some data on the model so you can react with that in the View. The Sintax as described in some blogs is:
[UIHint("TemplateToUse",null,"Variable1", "Value1", "Variable2", "Value2", ...)]
public string Something { get; set; }
And then I try to access this on the View with ViewData.ModelMetaData.AditioanlValues but the array returns empty!
Anyone have implemented this already to give me a "Hint" on how to use UIHint for this?
As of MVC3 you can use the AdditionalMetadataAttribute
[AdditionalMetadata("Source", "ThisIsACustomValue")]
which is then accessed in the view as
ViewData.ModelMetadata.AdditionalValues["Source"];
see http://msdn.microsoft.com/en-us/library/system.web.mvc.additionalmetadataattribute(v=vs.98).aspx
check this out:
http://www.mikevdm.com/BlogEntry/Key/Using-UIHint-With-ControlParameters-in-MVC
Related
I get data from my database (Firebase database). This is a document with several data, including a Array with GeoPoint fields.
var documents = await CrossCloudFirestore.Current .Instance .Collection("Activity") .GetAsync();
My object is defined like this in my Model class: public class Activity { public object elapsedTime { get; set; } public object positions { get; set; } ...... }
It works. I can have the data on my Activity class.
However, I would like to know how I can access this data because foreach loops do not work for object types. Maybe I need to redefine my Activity Class ?
Thx :=)
Edit :
You can see here my firebase :
And then the result of the request :
In your scenario , the property is dynamic for each object , I would suggest you deserialize the root level as a dictionaryand then get the data you want .
Items = JsonConvert.DeserializeObject<Dictionary<string, YourClass>>(content).Values.ToList()
Oh before this, Newtonsoft plugin is required .
Refer to
Deserialize JSON into readable format
It works ! :)
To do it, I defined Array (from firestore) as IEnumerable on my C# class, with the same name from firestore to c#.
And then, here is my query and the line to get my objects converted.
I have post request that contains the key "Items[]" with a value like "2,3,12".
I have a controller method that uses the following input model.
public class InputModel
{
public int[] Items { get; set; }
}
Currently "Items" never get set.
Am I doing something wrong (wrong type in my input model, missing an attribute etc) or is there no built-in functionality for this kind of binding?
You really need to post an array of integers? Send up a comma-delimited list like so in the form post:
Items=1,2,3
Spaces between the 1, 2, 3 wouldn't matter.
I'm using a DCV as a property in the View Model.
Everything works fine but what about custom sort?
Say I have a string property in my model which should be sorted alphanumerically.
How can I achieve such thing?
UPD:
Model:
public class MyModel
{
///...
public SomeProperty {get;set;}
}
xaml:
<data:DataTextColumn Binding={binding path=SomeProperty}, canusersort=true />
When sorting within the datagrid, the property gets sorted with disregard to alphanumeric order, i.e. in a regular string way. I'd like to apply my custom sort, e.g. by introducing my own IComparer. No API is available at least as I know of it.
Any clues?
The DomainCollectioView has special collection:
SortDescriptions
You could add next code in Your ViewModel:
DCV.SortDescriptions.Add(new SortDescription("SomeProperty ", ListSortDirection.Ascending));
I have struts page where the text boxes are with dynamic ID and wanted to get this values into Action class. Can someone please help me with the code plz.
Why did no one answer this question? Its a bit late to answer this question though. Well append all the data of textboxes in some format like json. Your URL will look something like /someclass.action?knownvariable=[{textbox1:value1},{textbox2:value2}] and pass it as one variable whose name is fixed. In Action class these data can be accessed.
Silpa, probably remove that parameter as below and use getter setter methods. Hope this helps.
public String retrieveDataFromDB() {
// Do something here
return "SUCCESS";
}
public void setKnownvariable(String knownvariable){
this.knownvariable=knownvariable;
}
public String getKnownvariable(){
return knownvariable;
}
private String knownvariable;
Suppose i have the following class.
public class Location
{
public Id { get; set;}
public Name { get; set;}
}
And i have a WebPage called Location that looks like this.
txtId
txtName
txtCountStaffWorkersAtLocation
txtCountVehiclesAtLocation
txtCountNonStaffWorkersAtLocation
txtCountetc
listViewPersonnel
listViewVehicles
Right now i'm calling a repository to display the Location fields on the view, but i'm confused as to what the correct method would be to get and display the data for the other fields. They obviously have very little to do do with the Location Class.
Do i put the Counts in the Location Class and fill them in when i set up the Location class from the database?
Do i have a struct object somewhere that has just has these count fields?
What do you guys normally do with object being displayed on a page that have very little to do with the Domain Object?
Thanks
I'd recommend implementing StaffPersonnel, NonStaffPersonnel, and Vehicles as properties on the Location object, with each of those properties returning a collection of the associated objects. Then for the counts, you could properties from a location object as follows:
loc.Vehicles.Count
loc.StaffPersonnel.Count
loc.NonStaffPersonnel.Count