Home > Blockchain >  Getting data from database using SQL but hide my placeholder in textbox in ASP.NET Core
Getting data from database using SQL but hide my placeholder in textbox in ASP.NET Core

Time:12-09

I get data from a database using a SQL query in which I search for data and display that data. But in the textbox it already have a value 0 that hides my placeholder. 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:

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:

public class inputModel
{
    public string? areaunit { get; set; }
    public int area { get; set; }
    public int price { get; set; }
}

Rent model:

public class RentModel
{
    public List<eHouse.Models.RentModel>? Data { get; set; }
    public List<string>? SearchList { get; set;}
    public inputModel? Input { get; set; }
}

CodePudding user response:

Make the property nullable by changing the price declaration to:

public int? price { get; set; }

When the price property is declared as int it has 0 value by default. Therefore, the placefolder doesn't applied.

  • Related