简体   繁体   English

直接从ASP.NET MVC模型绑定数据

[英]Binding data directly from model of asp.net mvc

I developed a textbox control which shows rounded off data on blur and actual data on focus . 我开发了一个文本框控件,该控件在blur显示舍入数据,在focus上显示实际数据。 currently this is being done using JS and value change has no relation with ASP.NET model. 当前,这是使用JS完成的,并且值更改与ASP.NET模型无关。

Is it possible to add two properties to model and bind them to these events? 是否可以添加两个属性来建模并将它们绑定到这些事件? ie, If I have A & B, on blur A should be bound and on focus B should be bound. 即,如果我有A和B,则在blur A上应绑定,在focus B上应绑定。 And each time when user modifies B, the changed value should be reflected in A (after rounding off). 并且每次用户修改B时,更改的值都应反映在A中(四舍五入后)。

I checked many websites, but I couldn't understand any of it. 我检查了许多网站,但我听不懂。 Few of them are, 他们很少

I'm assuming what you're after here is having both the rounded and actual data on post. 我假设您要处理的是在发布后同时包含四舍五入和实际数据。 If so, there's a better way than actually posting both. 如果是这样,有比实际发布两者更好的方法。 Just add a property to your view model that returns the rounded data: 只需将一个属性添加到您的视图模型即可返回四舍五入的数据:

public decimal Data { get; set; }

public int RoundedData
{
    get { return Convert.ToInt32(Math.Round(Data, 0)); }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM