繁体   English   中英

在我在 package 管理器中更新包后,我的提交按钮失去了功能并且什么都不做

[英]After I did update-package in the package manager my submit button has lost is functionality and does nothing

我有一个注册表单,有两个输入密码和密码确认。 当我输入不同的值时,我希望它显示错误消息为“密码应该匹配”或其他内容。 所以我搜索了一下,发现 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, new { htmlAttributes = new { @class = "form-control", @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, new { htmlAttributes = new { @class = "form-control", @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, new { htmlAttributes = new { @class = "form-control", @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">E-mail</label>
                <div class="col-md-12">
                    @Html.EditorFor(model => model.User.mail, new { htmlAttributes = new { @class = "form-control", @required = "required", @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, new { htmlAttributes = new { @class = "form-control", @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, new { htmlAttributes = new { @class = "form-control", @type = "text", @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, new { htmlAttributes = new { @class = "form-control", @type = "text", @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, new { htmlAttributes = new { @class = "form-control", @type = "text", @readonly="readonly", @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, function (index, 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, function (index, item) {
                                var optionhtml = '<option value="' + item.Value + '">' + item.Text + '</option>';
                                $("#ilce").append(optionhtml);
                            });

                        } else {
                            $.each(sonuc.text, function (index, 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>

ajax 调用的方法是:

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:获取区 kullanici:用户地址:地址 sonuc:结果提示:类型

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM