简体   繁体   中英

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 . currently this is being done using JS and value change has no relation with ASP.NET model.

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. And each time when user modifies B, the changed value should be reflected in A (after rounding off).

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)); }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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