ASP.NET MVC how to bind custom model to view
Date : March 29 2020, 07:55 AM
wish helps you You can use the ViewData[], but the best way would be to actually create a view class and return that. So let's say the view you want to send the data is called Contacts. Create a new View class and return that. so instead of this: public ActionResult Contacts(){
ViewData["contacts"] = arrayOfContacts[];
...
return View();
}
public class ContactsView(){
Object[] ContactsList {get;set;}
}
public ActionResult Contacts(){
...
return View(new ContactsView(){
ContactsList = arrayOfContacts[];
});
}
... Inherits="System.Web.Mvc.ViewPage<ContactsView>" ...
Model.ContactsList
object[] arrayOfItems = (Object[])ViewData["theContactsList"];
|
Should I use custom model binder to bind view model to entity?
Date : March 29 2020, 07:55 AM
seems to work fine Short answer would be No, you should not ModelBinder by itself is part of ASP.NET MVC infrastructure. If you would take a look at ASP.NET MVC pipline (PDF) you would see that it's job is to convert a posted web form data (a string basically) or query string from URL to an instance of particular class.
|
How to bind custom dependecy property to control's view model?
Tag : chash , By : gorbiz
Date : March 29 2020, 07:55 AM
Does that help What you describe is a common misconception that all views should have a view model. However, it is usually far simpler (and more appropriate) for UserControls that are used as controls to simply use their own DependencyPropertys. The problem with your method is that you have assigned the UserControl DataContext internally, so it cannot be set from outside the control. The solution is to not set the DataContext internally, but instead to use a RelativeSource Binding to access the UserControl DependencyPropertys like this: <TextBlock Text="{Binding DateCtrl, RelativeSource={RelativeSource
AncestorType={x:Type YourLocalPrefix:MyControl}}}" />
<TextBlock Text="{Binding YourViewModelProperty.DateVM, RelativeSource={RelativeSource
AncestorType={x:Type YourLocalPrefix:MyControl}}}" />
|
How to bind custom model class in mvc
Date : March 29 2020, 07:55 AM
This might help you You could do this by creating a view model and using a .GroupBy() clause public class TVSerialVM
{
public string SeriesName { get; set; }
public string SeasonNo { get; set; }
public string ImageUrl { get; set; }
}
List<TVSerialVM> model = tvContext.TvSerials.Where(t => t.Series_Name == serial)
.GroupBy(t => new { t.Series_Name, t.Season_No, t.Image_Url_Big })
.Select(t => new TVSerialVM
{
SeriesName = t.Key.Series_Name,
SeasonNo = t.Key.Season_No,
ImageUrl = t.Key.Image_Url_Big
}).ToList();
|
How to bind app's view-model to custom element using a promise?
Date : March 29 2020, 07:55 AM
Hope that helps I would like to bind a value present in my app.js view-model to a custom element, but I can't seem to get bind to work properly when the value of images is set from a Promise. , Try to return the promise in the activate: activate() {
return this.api.mockGet('gallery')
.then((images) => this.images = images);
}
|