如果我在 MVC 文本框 Asp.net 输入卡诺,则不显示结果



我正在创建一个汽车零售系统。 如果我输入正确的Carid相关汽车信息,我需要显示,将在下面的文本框中播放。 我附上了下面的屏幕截图图像。 我需要计算日期不同的开始日期和结束日期,以计算C#零售系统的零售费用 我是这样写的选择 car_id,cust_id,到期,DATEDIFF(GETDATE((,due( 作为租赁中的 ELAP,其中 car_id = ?

在 Asp.net MVC中,我不知道如何写。 我尝试过的东西附在下面。

截图图片 在此处输入图像描述

代码 I 绑定

表单设计

<div class="row">
<div class="col-sm-8">
@using (Html.BeginForm("Save", "return", FormMethod.Post, new { id = "popupForm" }))
{
<div>
<h4> Registation</h4>
</div>
<div class="card-action">
<label class="form-label">Car ID</label>
<input type="text" id="carno" name="carno" class="form-control" placeholder="carno" required />
</div>

<div class="card-action">
<label class="form-label">Customer ID</label>
<input type="text" id="custid" name="custid" class="form-control" placeholder="Customer ID" required />
</div>

<div class="card-action">
<label class="form-label">Date</label>
<input type="text" id="date" name="date" class="form-control" placeholder="Date" required />
</div>

<div class="card-action">
<label class="form-label">Days Elapsed</label>
<input type="text" id="elap" name="elap" class="form-control" placeholder="Date" required />
</div>

<div class="card-action">
<label class="form-label">Fine</label>
<input type="text" id="fine" name="fine" class="form-control" placeholder="Fine" required />
</div>

<div class="card">
<input type="submit" value="Save" class="btn btn-default" />
</div>
}
</div>
</div>

jQuery使用 jquery 搜索数据

<script>
getProductcode();
function getProductcode() {
$("#carno").empty();
$("#carno").keyup(function (e)
{
var q = $("#carno").val();
$.ajax({
type: "POST",
url: '/return/Getid?carno=' + $("#carno").val(),
dataType: "JSON",
success: function (data)
{
console.log(data);
$('#custid').val(data.custid);

},
error: function (xhr, status, error)
{
//  alert("The barcode entered is not correct");
}
});
return true;
});
}
</script>

返回控制器

[HttpPost]
public ActionResult Getid(String carno)
{
carrentEntities1 db = new carrentEntities1();
var carn = (from s in db.rentails where s.carno == carno select s.custid).ToList();
return Json(carn, JsonRequestBehavior.AllowGet);
}

我不知道如何将日期写成计算天数。 在这个没有显示结果的情况下,我测试了Custid,它没有发挥。

数据库字段

id  carno   custid  fee   sdate      edate
1   1        1     1200  2019-12-09  2019-12-19
2   1        1     20000 2019-12-01  2019-12-31
3   A0001    1     3434  2019-12-09  2019-12-27

首先,您应该通过此链接学习如何在sql中使用DATEDIFF方法

其次,在服务器端(Asp.net MVC(,您只需返回 ."优先或默认"而不是 。要列出。 仅仅是因为,正如我所看到的,在客户端你只得到一个项目($('#custid'(.val(data[0].custid(;(

最后,在我看来,keyup 事件应该与去抖动模式相结合,以避免不必要地调用服务器太多时间。

最新更新