【发布时间】:2022-06-18 00:40:35
【问题描述】:
我只需要返回通过来自 SQL Server 视图的 http 请求收到的数字的整数部分,例如:
如果数据库中的数字是 1234,我需要接收值 1234,但 asp net 框架返回 1234.0。
小数点后的零是我的问题。
尽管我的列是十进制格式,但所有保存的值都是整数。我无法更改此视图的列数据类型。
我的视图仅由两列组成:
PERSON_CODE(十进制(6,0),空)
PERSON_NAME (varchar(115), null)
我已经尝试使用 [DisplayFormat(...,但没有区别,我的返回总是小数点后的 0
public class VW_PERSONS
{
[Key]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0}")]
public decimal PERSON_CODE { get; set; }
public string PERSON_NAME { get; set; }
}
我的控制器:
[HttpGet]
public object GetPersonByCode(decimal PERSON_CODE)
{
try
{
return new Business.Person().GetPersonByCode(PERSON_CODE);
}
catch (Exception ex)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Util.GetExceptionMessages(ex)));
}
}
在我的企业内部:
internal PersonModel GetPersonByCode(string PERSON_CODE)
{
using (ExtranetEntities extranet = new ExtranetEntities())
{
int CODE_PERSON= int.Parse(PERSON_CODE);
return new ContatoModel(extranet.VW_PERSONS.FirstOrDefault(r => r.PERSON_CODE == CODE_PERSON));
}
}
谁能帮我解决这个问题?
【问题讨论】:
标签: c# .net asp.net-mvc .net-4.8