Hello,
which method do you prefer to update my newly saved customer with the last autoincremented Id ?
Do you see any disadvantage in one of both methods?
CustomerRepository.cs
public int AddCustomer(Customer customer)
{
//....
return lastID;
}
BillingViewModel.cs
//Method 1
SelectedCustomer.Id = _customerRepo.AddCustomer(Sel...
I'm using AutoMapper to map between a Linq Domain object and a ViewModel to display an Edit Form to the user which works perfectly.
When they click submit I'd like to know the best way to map the ViewModel back to a Linq entity and persist it to the database.
The Linq entity I'm using has multiple collections of other entities (ie one-...
Hi.
I didn't find a solution for this but I think it should be doable.
I have a number of items in a collection and want to select some of them. Each item has a CanInclude property containing the elements that can be selected if itself is already selected.
Item1 CanInclude: Item4, Item5
Item2 CanInclude: Item3, Item4
Item3 CanInclude:...
Hello all,
When I press the submit button and access the Controller my ViewModel is empty. I don't know why this is happening, I have similar code to this on the other views and they do pass through data.
Controller
public ActionResult DeleteCategory(int id)
{
var data = _service.GetIndividualCategory(id);
...
I've seen it all over SO, blogs, and books, where the authors tell you add ViewModels specific to your View in your Model projects as wrappers for your underlying model objects. The idea is to make it very simple and targeted when you go to do model binding to the View. Here is a good example: Rendering and Binding Drop Down Lists using ...
I have recently parametrized my ViewModel's contructor. Before that, I was doing this in my window:
<Window.DataContext>
<vm:MyViewModel />
</Window.DataContext>
The framework instantiated the ViewModel for me.
I know I can set DataContext in code but I would prefer a XAML way so designer can display my test data when designing.
...
Background:
I'm trying to implement a tab control. The tabs are as follows:
| Funds | Companies | Groups |
and are implemented as follows:
<ul class="ActionControl">
<li>
<%=Html.ActionLink(string.Format("Funds ({0})", Model.Summary.FundCount)
, "ResultsList", new {selectedTab = "Funds"} ) %>
</li>
//...
Assuming you wanted to develop your Controllers so that you use a ViewModel to contain data for the Views you render, should all data be contained within the ViewModel? What conditions would it be ok to bypass the ViewModel?
The reason I ask is I'm in a position where some of the code is using ViewData and some is using the ViewModel. I...
I am trying to properly accomplish the following. I have a UserControl (ProgramView). It has a viewmodel (ProgramViewViewModel). ProgramView is consumed as a child control within a Window (ProgramWindow). ProgramWindow has a public property ProgramId, so the consumer of the window can specify the desired Program (data entity) to show. Pr...
I have a UserControl with some custom dependency properties bound to a clr property in the ViewModel. The ViewModel has application logic where I deal with the TextPointer/TextRange classes with a FlowDocument.
Should I put that stuff into the code-behind of the UserControl or in the ViewModel?
ranges.Clear();
TextRange ran...
Should my ViewModel encapsulate the Services needed to populate it?
Currently I'm doing it as follows:
public PartialViewResult Companies(SearchViewModel search)
{
search.Summary = _entitySearchService.GetSearchDataSummary(search.SearchExpression);
search.PagedCompanies = _companyService.GetPagedEntities<Company>(search.SearchE...
I've been looking on forums for 2 days now and can't find a good answer so I'll just post it.
I appear to be having a problem posting JSON back to the controller to save. The JSON should map to model view but it keeps getting default(constructor)values rather then the values from the POST.
We have a series of JS widgets that contain a...
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ProductViewModel>" %>
<%= Html.DisplayFor(m => m.Product.Name) %>
Does not work. It says: "The type arguments for method ... cannot be inferred from the usage. Try specifying the type arguments explicitly."
...
In my viewmodel, I have a list (ObservableCollection) containing items. In the view, this list is displayed in an ItemsControl. In each row, there is a "Delete" button. I want the command behind the button to remove the item from the list.
<ItemsControl ItemsSource="{Binding myList}">
<ItemsControl.ItemTemplate>
...
...
How do I get properties in my BLL passed down to a ModeView. For example, I have this class in a separate Class Library:
[MetadataType(typeof(PersonMetaData))]
public partial class Person
{
[Bind(Include = "PersonId,DepartmentId,FirstName,LastName,Active,DateAdded,DateDeleted")]
public class PersonMetaData
{ ...
<DataTemplate DataType="{x:Type vm:SalesViewModel}">
<vm:Sales>
</DataTemplate>
Whats the meaing of the above code in wpf resource file?
...
After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf (both highly recommended!), I began to implement some of their ideas.
One of the cool things they do, is not only to use AutoMapper to map your entities to some viewmodel, but automate this with an AutoMapViewResult:
public class EventsControlle...
Hi
I have page with a simple table and advanced search form. I pass List<Customers> to the model:
View(List<Customers>);
So what is best way to pass and return data to the search form? I want to use validation or something but I think passing data through ViewData is not good idea. Any suggestions?
...
Here is my database Structure
Languages
LangID PK
LangName nvarchar(100)
Category
CatID Pk
IsActive Bit
CategoryText
CatID FK
CatName nvarchar(200)
LangID Int
Language
LangID | LangName
1 | English
2 | French
Category
CatID | IsActive
1 | True
2 | True
3 | True
CategoryText
CatID | CatName | ...
Page/ViewModel expose a Tab Control with Couple tab Items on that page. Each Tab Item has their own View Models. First tab load when page loads. How could I pass an object to this tab Item before it loads with the page. View models are independent. Child which is Tab item view model needs to grab property from PageVievModel.
...