Why does page not update after refresh when .cshtml changes

我是研究僧i 提交于 2019-12-10 14:20:34

问题


I am trying out Blazor and i do not understand why when changing a component after refreshing the browser page it does not update ? Shouldn't the client update itself similar to how angular does?

It only refreshes when i restart the blazor server.

Index.cshtml

@page "/"

<h1>Hello, world!</h1>

If i change lets say the text inside the <h1> to Hello people , i save the project and i refresh the page ( as i am advised in the Blazor tutorial) shouldn't i see Hello people ?


回答1:


I guess you are running the app with the debugger connected? this prevents the recompilation. You need to:

Press Ctrl-F5 to run the app without the debugger. Running with the debugger (F5) isn't supported at this time.




回答2:


After Asp.net Core 3.0, Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:

Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.

Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:

services
    .AddControllersWithViews()
    .AddRazorRuntimeCompilation();

or

services.AddMvc().AddRazorRuntimeCompilation();  



回答3:


You should rebuilt your project... Very simple... Saving your project is not enough. The newly built C# .dll files should be downloaded in the user browser before you see the changes. Actually, this has nothing to do with Blazor.

Auto rebuild feature is soon to be introduced in Blazor(specific to Blazor projects only, at least for the time being.)...Just like Angular.




回答4:


If you go into Tools > Options > Keyboard and search in the "Show commands containing" search box search for "BrowserLink". Find the option that says "OtherContextMenus.BrowserLink.RefreshLinkedBrowsers" by default this is set to CTRL+Alt+Enter. Click "Remove" and then select the "Press Shortcut Keys" input and press Ctrl+S. Next (just to the left of the input) change Use new shortcut in "Global" to be "Text Editor". Click "Ok" until the window has closed. Now Visual Studio shares CTRL+S with both Saving files and Refreshing linked browsers.

(This will only work if your text editor .cshtml, .css, .js, etc. files in the edit window are the active selections) WARNING: if you don't set it to something other than global then it will override the shortcut for Save and you won't be able to save your files.



来源:https://stackoverflow.com/questions/54106058/why-does-page-not-update-after-refresh-when-cshtml-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!