• 0

ASP.NET MVC5 CSHTML (Razor) Issues


Question

I really like the @Html.EditorFor(m => m.Foo) expressions and such.

There are a few issues though,

1. Refactoring the Model does not refactor the CSHTML (I am actively working on the model so its a big issue)

2. Rebuilding does not build the CSHTML files to tell me that it no longer compiles. This becomes a runtime error.

3. IdFor gets the Id of an EditorFor form field. I used that in a "var foo = $('#@Html.IdFor(m => m.Foo)');" but at that point it becomes nasty. Ideas?

Link to comment
https://www.neowin.net/forum/topic/1248318-aspnet-mvc5-cshtml-razor-issues/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

If you're still actively working on the model then I would use Html.EditorForModel(m => m) and let it scaffold on-the-fly until your model has stabilized. Otherwise you have not many other options other than updating your views as your model matures. When done you can write a custom editor for your model (in EditorTemplates) and you won't have to change your views that use EditorForModel()

  • 0

If you want to refactor a field (assuming you're using Visual Studio), you can press CTRL+R, R or F2 and it'll open a window to rename a model, method or property, which will propagate the change to everything that references it.

 

I also recommend you look into ReSharper, which will quickly highlight errors like referencing broken objects when a change occurs. It's a superbly nice addition to VS, even if it can bloat VS at times.

  • 0

1. You need something like ReSharper to do this. Microsoft doesn't think this is a big enough problem.

 

2. Have you enabled the MvcBuildviews? This might increase compile times up to tenfold. http://blogs.msdn.com/b/jimlamb/archive/2010/04/20/turn-on-compile-time-view-checking-for-asp-net-mvc-projects-in-tfs-build-2010.aspx

 

3. What are you trying to do with the field? If you want to just use the value you can do

var foo = @Model.Foo;
  • 0
  On 27/02/2015 at 21:13, night_stalker_z said:

1. You need something like ReSharper to do this. Microsoft doesn't think this is a big enough problem.

 

2. Have you enabled the MvcBuildviews? This might increase compile times up to tenfold. http://blogs.msdn.com/b/jimlamb/archive/2010/04/20/turn-on-compile-time-view-checking-for-asp-net-mvc-projects-in-tfs-build-2010.aspx

 

3. What are you trying to do with the field? If you want to just use the value you can do


var foo = @Model.Foo;
That is a bloody big problem to me! Bad Microsoft, Bad!

MvcBuildviews sounds useful, thanks.

Client Side JavaScript Foo binded to the model - getting EditorFor generated fields (via jQuery $("#ObjectIdHere")) via JS to do some logic.

This topic is now closed to further replies.
  • Posts

    • That explains my recent issues with classic Outlook. I can see the FORMS2 folder has resolved the issue on my system.
    • Brave 1.79.126 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. Brave 1.79.126 changelog: Fixed crash when clicking on shields panel in certain cases. Fixed crash on navigation when a Google sign-in request has been triggered. (#46769) Fixed crash when Leo generates empty list when clicking on “Suggest questions” while using BYOM (Bring Your Own Model). (#46843) Fixed issue importing from Trezor wallet when Trezor Connect is outdated. (#46660) Upgraded Chromium to 137.0.7151.119. (#46911) Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • LeafView 3.6.5 by Razvan Serea LeafView is a fast, open-source image viewer built with Electron. It offers a sleek, minimal UI for fast and efficient image browsing. Supporting various formats, LeafView ensures a smooth viewing experience with essential features like zoom, rotation, and slideshow mode. Designed for simplicity and performance, it utilizes hardware acceleration for smooth rendering and supports touch gestures for seamless navigation. LeafView key features: Lightweight & Open-Source – Minimal resource usage with a clean, efficient design Electron-Based – Cross-platform compatibility with modern UI Multiple Image Format Support – Opens JPG, PNG, GIF, BMP, and more Smooth Rendering – Hardware acceleration for fast performance Essential Image Controls – Zoom, rotate, and slideshow mode Touch Gesture Support – Seamless navigation on compatible devices Minimal UI – Focused on simplicity and ease of use LeafView 3.6.5 changelog: Update electron to v36.5.0 Download: LeafView 3.6.5 | Portable | ~100.0 MB (Open Source) View: LeafView Website | Other operating systems | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Which is why I continue to use Open Shell for my start menu. your best course of action is to install a third-party Start menu
  • Recent Achievements

    • First Post
      Fuzz_c earned a badge
      First Post
    • First Post
      TIGOSS earned a badge
      First Post
    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      700
    2. 2
      ATLien_0
      280
    3. 3
      Michael Scrip
      208
    4. 4
      +FloatingFatMan
      196
    5. 5
      Steven P.
      130
  • Tell a friend

    Love Neowin? Tell a friend!