viewmodel

ASP.NET MVC Complex View Mapping

雨燕双飞 提交于 2019-12-23 00:52:13
问题 I have looked around and found some close answers, but I haven't seen one yet like this: Using Entity Framework I have the following: A Role model: public class Role { [Key] public short RoleId { get; set; } public string RoleName { get; set; } public string RoleDescription { get; set; } } A User model: public class User { public int Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Username { get; set; } //more fields etc... public virtual

How to navigate from one view to another view from viewmodel in silverlight?

旧城冷巷雨未停 提交于 2019-12-22 19:40:13
问题 I have one ViewModel and two Views. How can I navigate to View2 from ViewModel. I read somewhere that we need to use PRISM, for opening multiple Views from ViewModel in Silverlight. Is there any alternative for PRISM? 回答1: Ideally you do not want to use view logic in your viewmodel. Your viewmodel should not know anything about the view. It would be a better idea for your viewmodel to set a property letting the view know it's time to navigate. Here's an example: ViewModel : using System

Using TempData dictionary prevents RedirectToAction from working

陌路散爱 提交于 2019-12-22 12:36:19
问题 I want to add view model to TempData in order to pass it to another controller like this (referring to last 2 lines): [HttpPost("register")] public async Task<IActionResult> Register(RegisterViewModel rvm) { if (ModelState.IsValid) { var result = await _authManager.RegisterUserAsync(rvm.FullName, rvm.Email, rvm.Password); if (result.IsSuccessful) { return RedirectToAction("Login", "Home", new { message = result.Message }); } else { TempData["rvm"] = rvm; return RedirectToAction("Register",

Change default “The {0} field is required” (ultimate solution?)

时光怂恿深爱的人放手 提交于 2019-12-22 11:35:32
问题 Good day! I've the following ViewModel class I use for login form: using System.ComponentModel.DataAnnotations; ... public class UserLogin : IDataErrorInfo { [Required] [DisplayName("Login")] public string Login { get; set; } [Required] [DisplayName("Password")] public string Password { get; set; } [DisplayName("Remember Me")] public bool RememberMe { get; set; } #region IDataErrorInfo Members // This will be a Model-level error public string Error { get { if (!WebUser.CanLogin(Login,

ASP.NET MVC - Job of Controllers

做~自己de王妃 提交于 2019-12-22 10:54:53
问题 I think I'm beginning to be confused with the job of a controller in MVC. I have a service that exposes five functions: list packages in queue get package delete package accept package deny package My ASP.NET MVC controller depends on this service, and can generally execute a service call on an Action. I'm happy so far. The second part is then building the ViewModel result. If I do this inside of the controller, the controller now has an exploding dependency list -- each action added

MVC2 Modelbinder for List of derived objects

故事扮演 提交于 2019-12-22 10:49:03
问题 I want a list of different (derived) object types working with the Default Modelbinder in Asp.net MVC 2. I have the following ViewModel: public class ItemFormModel { [Required(ErrorMessage = "Required Field")] public string Name { get; set; } public string Description { get; set; } [ScaffoldColumn(true)] //public List<Core.Object> Objects { get; set; } public ArrayList Objects { get; set; } } And the list contains objects of diffent derived types, e.g. public class TextObject : Core.Object {

Storing Model ID in ASP.NET MVC ViewModel, Security issues

萝らか妹 提交于 2019-12-22 09:37:59
问题 In my MVC application I have a page for a user editing their account details such as email address, password etc. In my database a User table holds this data and the primary key is UserId. On the ChangeAccountDetails view I have created I pass a ViewModel with the data the user should be able to modify on their account. I also store the UserId in the ViewModel which is rendered into a hidden field on my actual view. I have a concern that this is not safe for the reason that on POST action to

What is the correct way to pass data between view models?

你说的曾经没有我的故事 提交于 2019-12-22 08:36:56
问题 I've just started with MVVM and I have been reading up on it and doing some examples. I've managed to create an application that will read from the database and then populate into a listbox. I am having difficulty in trying to link up the selected item into another view and then do a bit of processing in that views viewModel. Please can somebody explain to me the correct way to get the currently selected item from view1 listbox and then on view2 label just to output the selected item? Here is

Databinding 2 comboboxes Issue

我与影子孤独终老i 提交于 2019-12-22 00:11:58
问题 I have 2 comboboxes. If i select a Activity in the 1st one, the related sub activities should be displayed in the second combobox. The code looks fine as per MVVM style but when i select an activity on 1st one, the related subactivities in the 2nd combobox are not synched. Here is my code: View <Window x:Class="TestDGCombosBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace

Implementing ASP.NET MVC 3 Interface Model Binding (with ViewModel)

最后都变了- 提交于 2019-12-21 23:18:09
问题 I just learning ASP.NET MVC 3 and I'm a bit confused on how I can implement something like what is shown in this link: http://www.codethinked.com/easy-and-safe-model-binding-in-aspnet-mvc Why I'm confused is most likely based on my ignorance in the subject. In the example on the page linked above, I see Justin is using a ViewModel that directly contains properties of his "Person" object. What I want to do is similar, but I want to have a ViewModel actually contain the domain class, which is