• 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

    • Tablet mode doesn't exist on public releases in Windows 11, but there is a very good option activated with a few registry tweaks they must be testing. I've been using it on an old Surface Pro and love it. Minimised taskbar with no pinned icons or Start button visible, only clock and settings (battery/wifi/sound) icons. When the whole thing is visible, the icons are much larger and easy to tap. Swiping up does shows it and if you continue, opens the Start Menu. Needs more work, like a single finger swipe for multitasking, and perhaps miniaturised widget/s visible on the left, but it works well and I think it even works with mouse & keyboard use (mine's forced always on). Reddit - https://preview.redd.it/what-w...51db8351dd56cbf6bc012397a20
    • A GUI wrapper makes something like this actually accessible for people coming from any other system. I do not want to ever touch the terminal, we are no longer in the 80's, so this is actually a massive help, even if the underlying software isn't actually great. Bullying should be called out, and I believe that's what this post is about. So I'm glad it's happened, and I hope that this dev, or someone else picks it back up and makes the Linux Desktop a touch more relevant in the modern world.
    • the point is you need new PCs with a dedicated co-pilot button lol
    • The problem is that LOUD and AGRESSIVE persons end up getting their way one way or another. In this case, the dodgy user was successful in making the dev quit the project. If the dev continued to work on it, their comments could well have had ramifications on others who may have wanted to try it, also thinking that what was said was true, and the tool may never have got traction. It's just flat out bullying, lets call it what it is, and needs to be addressed. Often bullies are the actual "snowflakes", who have often missed developmental milestones in childhood, or experienced trauma and as a result don't have the intellect or skills to manage their emotions. It often comes across as aggressive, much like this user. So while this user clearly has something going on, I do hope they seek help. As for the developer, I also hope they build some resilience, and experience the opposite of bullying via positive words from this news story. Calling them a "snowflake" is effectively bullying in itself, and that too needs to be called out. So I'm calling you out @noobient. Your point otherwise is valid. But we all need to have support too, and clearly there wasn't during this developers time of bullying. We as part of the tech community need to do better.
    • yeah it works on every version BUT the one on MacOS lol
  • Recent Achievements

    • First Post
      Gladiattore earned a badge
      First Post
    • Reacting Well
      Gladiattore earned a badge
      Reacting Well
    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      649
    2. 2
      ATLien_0
      256
    3. 3
      Xenon
      165
    4. 4
      neufuse
      143
    5. 5
      +FloatingFatMan
      108
  • Tell a friend

    Love Neowin? Tell a friend!