سؤال

I am a beginner to MVC

My View code

<script>
$(function () {
    $("#dialog-modal").dialog({
        autoOpen: false,
        width: 400,
        height: 500,
        resizable: false,
        title: 'Accounts',
        modal: true,
        open: function (event, ui) {
            var ln = '@Html.Raw(Json.Encode(Model.ln))';
            var profileID = '@Html.Raw(Json.Encode(Model.profileID))';
            var title = '@Html.Raw(Json.Encode(Model.title))';
            var active = '@Html.Raw(Json.Encode(Model.active))';
            alert(active);
            var link = '@Url.Action("accountPartial", "BillingProfile")?ln=' + ln + '&profileID=' + profileID + '&title=' + title + '&active=' + active;
                    //link = link.replace(-1, ln);
                    //link = link.replace(-2, profileID);
                    $(this).load(link);

                },
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                },
                show: {
                    effect: "blind",
                    duration: 200
                },
                hide: {
                    effect: "blind",
                    duration: 200
                }
            });
            $("#opener-modal").click(function () {
                $("#dialog-modal").dialog("open");
            });
        });
    </script>

My Controller action

public ActionResult accountPartial(string title,bool active,int ln = 0, int profileID = 0)
    {
        List<AccountCode> model = db.AccountCodes.ToList();
        ViewBag.ln = ln;
        ViewBag.profileID = profileID;
        ViewBag.title = title;
        ViewBag.active = active;
        return PartialView("_AccountPartial", model);

Here When i enter title having space (eg:Check Account) then my controller action "accountpartial" is not called and when i enter title without any space (eg:check) then my actionName is called What must the problem? Thanks in advance

هل كانت مفيدة؟

المحلول

It may be that the space in the title is not being url encoded correctly. Try using encodeURIComponent() to solve this.

var link = '@Url.Action("accountPartial", "BillingProfile")?ln=' + ln + '&profileID=' + profileID + '&title=' + encodeURIComponent(title) + '&active=' + active;

Just an idea. Can't be sure.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top