简体   繁体   中英

Why does returning partial view affect my styles from being applied to my partial view?

So,

I have bools for when to display a certain partial view and I noticed for one of my partial views, it displays correctly with the correct CSS styles and classes. However, my other partial view does not display correctly (I get no errors in console too) and I have narrowed it down to this line of code seeing how this makes the difference:

 @Html.ActionLink(@Culture.GetString("ResetPasswordViaQuestionAnswer"), "GetUserName", "Account", new { style = "color:black; background: none;" }) 

OR

    <a href="@Url.Action("GetUserName", "Account")">@Culture.GetString("ResetPasswordViaQuestionAnswer")</a>

Whenever I use @Html.ActionLink or @Url.Action to call my action to return my partial view, the CSS style breaks. None of my classes get properly added to my inputs and form elements.

The above calls this action:

        [AllowAnonymous]
        public ActionResult GetUserName()
        {
            LoginModel loginModel = new LoginModel();
            GetUserName getUserName = new GetUserName();
            loginModel.getUserName = getUserName;
            loginModel.DisplayResetPasswordDialog = true; 
            return PartialView("Login", loginModel);
        }

Which then goes to my Login partialview which inside a div contains:

@if(Model.DisplayChangePasswordDialog == true){
                    @Html.Partial("PasswordExp",new ViewModels.PasswordChangeViewModel())
               }else if (Model.DisplayResetPasswordDialog == true){
                    @Html.Partial("ResetUserPassword", new ViewModels.GetUserName())
               }else{
                     @Html.Partial("_login", Model)
            }

Something in what I have done above is breaking the CSS styles and classes from being attached to my inputs. The view is loaded but the view is loaded incorrectly. No styles or classes are applied.

Why?

You can't (or shouldn't) redirect to a partial view because you're not going to be getting your _Layout file that contains your css and js.

Instead you should redirect to a view containing your partial view. That view should have a reference to your layout file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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