如何解决在包管理器中执行 update-package 后,我的提交按钮失去了功能并且什么也不做
我有一个注册表单,有两个输入密码和密码确认。当我输入不同的值时,我希望它显示错误消息为“密码应匹配”或其他内容。所以我用谷歌搜索,发现 update-package 应该可以解决这个问题。然后我应用了这个解决方案来解决我的问题,现在,我的错误消息既不显示也不提交按钮工作。
我的注册视图:
<div class="container-fluid">
@using (Html.BeginForm("Register","User",FormMethod.Post,new { @class = "col-12" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal p-3 m-3 w-100 d-flex flex-column align-items-center">
@Html.ValidationSummary(true,"",new { @class = "text-danger" })
<div class="form-group w-100">
<label class="form-control-label col-md-12">Kullanıcı adı</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.kullaniciAdi,new { htmlAttributes = new { @class = "form-control",@required = "required" } })
@Html.ValidationMessageFor(model => model.User.kullaniciAdi,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Firma adı</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.firmaAdi,@required = "required" } })
@Html.ValidationMessageFor(model => model.User.firmaAdi,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Şifre</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.sifre,@required = "required",@type = "password" } })
@Html.ValidationMessageFor(model => model.User.sifre,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Şifre tekrar</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.sifreTekrar,@type = "password" } })
@Html.ValidationMessageFor(model => model.User.sifre,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">E-mail</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.mail,@type = "text" } })
@Html.ValidationMessageFor(model => model.User.mail,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Telefon</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.telefon,@type = "text",@required = "required" } })
@Html.ValidationMessageFor(model => model.User.telefon,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Ülkeniz</label>
@Html.EditorFor(model => model.Address.ulkeID,@readonly="readonly",@Value="Türkiye" } })
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Bulunduğunuz il</label>
<select class="form-control col-md-12" name="Address.sehirID" id="il" required></select>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Bulunduğunuz ilçe</label>
<select class="form-control col-md-12" name="Address.ilceID" id="ilce" disabled required>
<option>Bir İl Seçiniz</option>
</select>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Açık adresiniz</label>
<div class="col-md-12">
@Html.EditorFor(model => model.Address.acikAdres,@required = "required" } })
@Html.ValidationMessageFor(model => model.Address.acikAdres,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<label class="form-control-label col-md-12">Oluşturulma Tarihi</label>
<div class="col-md-12">
@Html.EditorFor(model => model.User.olusturulmaTarihi,@Value=sqlFormat } })
@Html.ValidationMessageFor(model => model.Address.acikAdres,new { @class = "text-danger" })
</div>
</div>
<div class="form-group w-100">
<div class="col-md-offset-2 col-md-12">
<input type="submit" value="Kaydol" class="btn btn-success" />
</div>
</div>
</div>
}
</div>
注册操作:
[HttpPost]
public ActionResult Register(RegisterVM model)
{
tblKullanici user = null;
tblAdres address = null;
if(model != null)
{
db = new DatabaseContext();
user = model.User;
address = model.Address;
db.tblKullanici.Add(user);
db.tblAdres.Add(address);
db.SaveChanges();
if (db.SaveChanges() > 0)
{
Session["login"] = model.User;
return RedirectToAction("Index","App");
}
}
ViewBag.Message = "Kayıt işlemi sırasında hata oluştu!";
return View(model);
}
jQuery
<script>
// ajax call to bring district and city info dynamically according to the city value
$(function () {
$.ajaxSetup({
type: "post",url: "/User/IlIlce",// target
dataType: "json"
});
$.extend({
ilGetir: function () {
$.ajax({
//sending data
data: { "tip": "ilGetir" },success: function (sonuc) {
//check result if ok then append it to selectlist
if (sonuc.ok) {
$.each(sonuc.text,function (index,item) {
var optionhtml = '<option value="' + item.Value + '">' + item.Text + '</option>';
$("#il").append(optionhtml);
});
} else {
$.each(sonuc.text,item) {
var optionhtml = '<option value="' + item.Value + '">' + item.Text + '</option>';
$("#il").append(optionhtml);
$("body").append(optionhtml);
});
}
}
});
},ilceGetir: function (cityID) {
$.ajax({
// then we get the districts with cityID
data: { "ilID": cityID,"tip": "ilceGetir" },success: function (sonuc) {
// deleting records
$("#ilce option").remove();
if (sonuc.ok) {
// disabled to false
$("#ilce").prop("disabled",false);
$.each(sonuc.text,item) {
var optionhtml = '<option value="' + item.Value + '">' + item.Text + '</option>';
$("#ilce").append(optionhtml);
});
} else {
$.each(sonuc.text,item) {
var optionhtml = '<option value="' + item.Value + '">' + item.Text + '</option>';
$("#ilce").append(optionhtml);
});
}
}
});
}
});
// invoke ilGetir to get city values
$.ilGetir();
// on change in city value
$("#il").on("change",function () {
// we get the id of selected value
var cityID = $(this).val();
// and pass it to the ilceGetir function to get the districts
$.ilceGetir(cityID);
});
});
</script>
public JsonResult IlIlce(int? ilID,string tip)
{
db = new DatabaseContext();
List<SelectListItem> sonuc = new List<SelectListItem>();
bool isSuccessful = true;
try
{
switch (tip)
{
case "ilGetir":
// we assign the city values in db to sonuc(result) variable
foreach (var sehir in db.tblSehir.ToList())
{
sonuc.Add(new SelectListItem
{
Text = sehir.sehirAdi,Value = sehir.sehirID.ToString()
});
}
break;
case "ilceGetir":
// we will fetch districts with sehirID(cityID)
foreach (var ilce in db.tblİlce.Where(il => il.bagliOlduguSehirID == ilID).ToList())
{
sonuc.Add(new SelectListItem
{
Text = ilce.ilceAdi,Value = ilce.ilceID.ToString()
});
}
break;
default:
break;
}
}
catch (Exception e)
{
// if we encounter an error
isSuccessful = false;
sonuc = new List<SelectListItem>();
sonuc.Add(new SelectListItem
{
Text = e.Message,Value = "Default"
});
}
// i return the results as json
return Json(new { ok = isSuccessful,text = sonuc });
}
ilce 意思是:区 sehir/il 都意味着:城市 sifre:密码 kullaniciAdi:用户名 电话:电话号码 ulke:国家 ilGetir : 获取城市 ilceGetir:取区 库拉尼奇:用户 地址:地址 声音:结果 提示:输入
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。