[英]Getting data from database using SQL but hide my placeholder in textbox in ASP.NET Core
I get data from a database using a SQL query in which I search for data and display that data.我使用 SQL 查询从数据库中获取数据,我在其中搜索数据并显示该数据。 But in the textbox it already have a value 0 that hides my placeholder.
但是在文本框中它已经有一个值 0 隐藏了我的占位符。 Kindly tell me any other solution.
请告诉我任何其他解决方案。
View:看法:
<input type="text" placeholder="price" asp-for="Input.price"
style="height: 50px; border-color: black; border-style:solid; margin-top: 5px; margin-bottom: 3px; border-radius: 5px;" />
Controller: Controller:
public IActionResult Rent(inputModel input, int PageNumber = 1)
{
var data = rdb.GetDataHouse();
var datas = rdb.GetDataHouse();
ViewBag.Data = datas.ToList().Take(7);
ViewBag.Totalpages = Math.Ceiling(data.Count() / 6.0);
if (!string.IsNullOrEmpty(input.areaunit))
{
data = data.Where(x => x.areaUnit == input.areaunit & x.area == input.area & x.price <= input.price).ToList();
}
data = data.Skip((PageNumber - 1) * 6).Take(6).ToList();
var viewModel = new RentModel
{
Data = data,
//SearchList = List<string>(),
Input = new inputModel(),
};
return View(viewModel);
}
Input model:输入 model:
public class inputModel
{
public string? areaunit { get; set; }
public int area { get; set; }
public int price { get; set; }
}
Rent model:出租model:
public class RentModel
{
public List<eHouse.Models.RentModel>? Data { get; set; }
public List<string>? SearchList { get; set;}
public inputModel? Input { get; set; }
}
Make the property nullable by changing the price
declaration to:通过将
price
声明更改为以下方式使属性可为空:
public int? price { get; set; }
When the price
property is declared as int
it has 0
value by default.当
price
属性声明为int
时,默认情况下它的值为0
。 Therefore, the placefolder
doesn't applied.因此,不应用
placefolder
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.