无法在asp.net mvc项目中使用telerik通知

时间:2016-02-17 13:46:45

标签: asp.net-mvc notifications telerik

我想在我的Asp.net Mvc项目中使用noty,但是因为我不能这样做,所以我更喜欢telerik。算法是,用户注册一个网页,在服务器端进行处理,如果成功,我想在客户端显示一条消息。以下是telerik通知的用法:

http://demos.telerik.com/aspnet-mvc/notification/index

这是我的来源:( HomeController / Register)

  [HttpPost]
public ActionResult Register(Users user)
{
    IAraclar tool = null;
    string uname = null;
    IKisiBL userBusinessRule = null;

    try
    {
        tool = new toollar();
        uname = tool.GetUserName(user.UserEmail);
        user.UserName = uname;

        USERS newDataUser = new USERS
        {
            USER_ID = 0,
            USER_EMAIL = user.UserEmail,
            USER_NAME = user.UserName,
            USER_PASSWORD = user.UserPassword,
            USER_ROLE_TIP = (short)user.UserRoleTipi,
            USER_KURUM_TIPI = (short)user.UserKurumTipi
        };

        using (LojmanEntities entities = new LojmanEntities())
        {


            entities.USERS.Add(newDataUser);
            entities.SaveChanges();
        }
    }
    catch (Exception ex)
    {

        tool.HataRaporla(ex);
        throw;
    }   
    //ViewData["SuccessMessage"] = SistemMesajlari.KayitTamamlandi_ok();
    return View();
 }

https://docs.google.com/document/d/11EoaOQysDa0FmNIawSZ1AafOh0pZ58W_Qku2Z3BnXWo/edit?usp=sharing

这是我的Register.cshtml,其中与上面的Action紧密结合:

 @model LojmanMVC.Domain.Entities.Users

@{
          ViewBag.Title = "Lojman Bilgi Sistemi Kullanıcı Kaydı";
}
      <h2>Lojman Bilgi Sistemi Kullanıcı Kaydı</h2>

<p id="sifresonuc"> </p>

@*prospective item that shows message*@
@(Html.Kendo().Notification()
    .Name("staticNotification")
    .AppendTo("#appendto")
)

@*classical form in mvc*@
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Lütfen kullanıcı bilgilerinizi giriniz: </legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserEmail) (Bakanlıkça verilen e-posta adresiniz)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserEmail)
            @Html.ValidationMessageFor(model => model.UserEmail)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserPassword)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(item => item.UserPassword, new { id = "password1" })
        </div>
        <div class="editor-label">
            <label for="male">Lütfen şifrenizi tekrar giriniz: </label>
        </div>
        <div class="editor-field">
            <input type="password" name="password2" id="password2" />
        </div>


        <div class="editor-label">
            <label for="male">Lütfen rolünüzü giriniz: </label>
        </div>
        <div class="editor-field">
            @Html.MyEnumDropDownListFor(m => m.UserRoleTipi)
        </div>

        <p>
            <input type="submit" id="registerButton" value="Kayıt Ol" />
        </p>
        <button id="showStaticNotification" class="k-button">Static in the panel below</button>
    </fieldset>
}

<script type="text/javascript">

    console.log("1");

    function checkPasswordMatch() {
        console.log("checkPasswordMatch");
        var password = $("#password1").val();
        var confirmPassword = $("#password2").val();

        if (password != confirmPassword) {
            $("#sifresonuc").html("Şifreler uyuşmamaktadır!");
            var $p = $("#sifresonuc");
            var $button = $("#registerButton");
            $button.prop('disabled', true);
            $p.css("background-color", "red").show(500);
        }
        else {
            $("#sifresonuc").html("");
            var $p = $("#sifresonuc");
            $p.css("background-color", "white").show(500);

            var $button = $("#registerButton");
            $button.prop('disabled', false);
        }

    }

    console.log("2");

    $(document).ready(function () {
        $("#password2").keyup(checkPasswordMatch);

    });

    console.log("3");

    function InputToLower(obj) {
        if (obj.value != "") {
            obj.value = obj.value.replace('İ', 'i').replace('I', 'ı').toLowerCase();
        }
    }

    console.log("4");

    $(function () {
        $("#registerButton").click(function (e) {
            console.log("5");
            // e.preventDefault();
            var errorSummary = $('.validation-summary-errors');
            console.log("6");
            if (errorSummary.length == 0) {
                $('#listError').remove();
                $('<div class="validation-summary-errors"></div>').insertAfter($('.validation-summary-valid'));
                $(".validation-summary-errors").append("<ul id='listError'><li>0 karakter giremezsiniz. OSI-122 </li></ul>");
            }
            else if (errorSummary.length == 1) {
                $('#listError').remove();
                $(".validation-summary-errors").append("<ul id='listError'><li>You cannot enter more than 20 characters.</li></ul>");
            }
            //return false;
            // place that sets notification
            console.log("7");
            var d = new Date();
            staticNotification.show(kendo.toString(d, 'HH:MM:ss.') + kendo.toString(d.getMilliseconds(), "000"), "info");
            var container = $(staticNotification.options.appendTo);
            container.scrollTop(container[0].scrollHeight);
            console.log("8");
        });

    });


</script>

https://docs.google.com/document/d/1t7g9K4v5BrIyFkHVCMxVowDUbMlT3P6Tsz-88d7YOuA/edit?usp=sharing

(因为尽管付出了很多努力,我仍然无法编写这些代码行,但我通过谷歌文档分享了这些代码)

当我运行代码时,页面中没有任何通知,&#34; 1,2,3,4&#34;出现在console.Function包含5在那里不起作用。我做错了什么?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我认为您应该尝试在registerButton函数中分配$document.ready()的处理程序,并尝试使用函数click分配unbind事件的处理程序/ bind

document.ready(function(){
    $("#registerButton").unbind("click").bind("click", function() {
         <your code here>
         ...
    });
});