viewmodel

Knockout how to get data-bind keys and value observables using element?

风流意气都作罢 提交于 2019-12-02 10:57:40
问题 I need to get data bind keys and value observable using element. <select id="selector" data-bind="options:selectOptions,value:selectedValue"></select> var ViewModel = { selectOptions:ko.observableArray([...]), selectedValue:ko.observable() ... some other stuff ... } In other viewmodel I can access dom element now I need to update element's binding context observable. how can I get data-bind keys and values? I need something like this { options:selectOptions, value:selectedValue } 回答1: ko

Knockout how to get data-bind keys and value observables using element?

…衆ロ難τιáo~ 提交于 2019-12-02 07:38:36
I need to get data bind keys and value observable using element. <select id="selector" data-bind="options:selectOptions,value:selectedValue"></select> var ViewModel = { selectOptions:ko.observableArray([...]), selectedValue:ko.observable() ... some other stuff ... } In other viewmodel I can access dom element now I need to update element's binding context observable. how can I get data-bind keys and values? I need something like this { options:selectOptions, value:selectedValue } ko.dataFor(element) will help. See - http://knockoutjs.com/documentation/unobtrusive-event-handling.html In your

Update viewmodel based on MainWindow event

断了今生、忘了曾经 提交于 2019-12-02 07:04:48
问题 I have a UdpClient, firing off a DataRecevied event on my MainWindow: public partial class MainWindow : Window { public static YakUdpClient ClientConnection = new YakUdpClient(); public ClientData; public MainWindow() { InitializeComponent(); Loaded += OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { ClientData = new ClientData(); ClientConnection.OnDataReceived += ClientConnectionOnDataReceived; } private void ClientConnectionOnDataReceived(object sender,

in asp.net-mvc, what is the best way to have a Base ViewModel to show dynamic content on the Site.Master page

会有一股神秘感。 提交于 2019-12-02 05:23:14
问题 i have an asp.net-mvc site and there is some information that i want to show on every page. I have created a class called BaseViewModel and each of the viewModel classes inherit from BaseViewModel. The Site.Master view binds to the BaseViewModel directly. Right now the base class has one property called MenuLinks. The menulinks property gets populated from a database call so on every controller action that is instatiating a ViewModel i am adding a new line: viewModel.MenuLinks = _repository

ASP.net MVC - Custom attribute error message with nullable properties

£可爱£侵袭症+ 提交于 2019-12-02 04:47:33
问题 I am having a property in my View Model which can accept integer and nullable values: [Display(Name = "Code Postal")] public int? CodePostal { get; set; } When I type in string values, how can display another message than the default one: The field Code Postal must be a number. Thanks 回答1: You could write a metadata aware attribute: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class MustBeAValidIntegerAttribute : Attribute, IMetadataAware {

Update viewmodel based on MainWindow event

别说谁变了你拦得住时间么 提交于 2019-12-02 04:18:37
I have a UdpClient, firing off a DataRecevied event on my MainWindow: public partial class MainWindow : Window { public static YakUdpClient ClientConnection = new YakUdpClient(); public ClientData; public MainWindow() { InitializeComponent(); Loaded += OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { ClientData = new ClientData(); ClientConnection.OnDataReceived += ClientConnectionOnDataReceived; } private void ClientConnectionOnDataReceived(object sender, MessageEventArgs messageEventArgs) { ClientData.Users = messageEvenArgs.ConnectedUsers; } } My

ASP.net MVC - Custom attribute error message with nullable properties

半城伤御伤魂 提交于 2019-12-02 01:02:22
I am having a property in my View Model which can accept integer and nullable values: [Display(Name = "Code Postal")] public int? CodePostal { get; set; } When I type in string values, how can display another message than the default one: The field Code Postal must be a number. Thanks You could write a metadata aware attribute: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class MustBeAValidIntegerAttribute : Attribute, IMetadataAware { public MustBeAValidIntegerAttribute(string errorMessage) { ErrorMessage = errorMessage; } public string

MVVM: Binding a ViewModel which takes constructor args to a UserControl

寵の児 提交于 2019-12-01 22:37:15
My WPF app has a MainWindow containing a usercontrol called TvshowGridView. MainWindow: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:NevermissClient" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:views="clr-namespace:NevermissClient.Views" x:Class="NevermissClient.MainWindow" x:Name="Window"> <Grid x:Name="LayoutRoot"> <views:TvshowGridView x:Name="TheTvshowGridView" Margin="8

send a ViewModel which contains a list with a Html.BeginForm (MVC 4)

余生颓废 提交于 2019-12-01 20:26:03
问题 My viewmodel contains a integer list, the problem I have is that when I send my modified form viewmodel, it is always equal to null. My ViewModel : public class testViewModel { public List<int> itemTest { get; set; } Action in my Controller : For example, I'll try to sum ​​the new values ​​entered into the form, but the sum calculated is always equal to 0, nothing changes. public ActionResult form(int nbre) { testViewModel montest = new testViewModel() { itemTest = new List<int>() }; for(int

MVC View: Type arguments Html helper DisplayFor cannot be inferred from the usage

主宰稳场 提交于 2019-12-01 17:54:12
I'm trying to make use of the extended HTML Helper DisplayFor in this View: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.SubscriptionsViewModel>" %> <% using (Html.BeginForm("TrainingSubscription", "Account", FormMethod.Post)) { %> <%: Html.DisplayFor(m => m.Subscriptions) %> <input type="submit" value="Save" /> <% } %> with the following ViewModel namespace MvcCms.Web.ViewModels { public class SubscriptionsViewModel { public string TrainingId { get; set; } public string Subject { get; set; } public IEnumerable