• 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

    • Ah .. lockout for suspicious activity. I bet they uploaded the SanDisk utility detected as malware
    • Microsoft 365 will soon disable outdated authentication protocols for file access by Usama Jawad On a fairly regular basis, Microsoft disables outdated protocols that are used to access its services. In the past few years, the company has deprecated Basic Auth in Exchange Online and cut access to Outlook for third-party apps relying on this protocol. Now, it has decided to get rid of old authentication protocols for file access across Microsoft 365 services. As reported by Bleeping Computer, Microsoft has posted a message on its Microsoft 365 Admin Center. Starting from mid-July 2025, the company will begin disabling legacy authentication protocols used to access files across Microsoft 365 and Office apps, SharePoint, and OneDrive. Essentially, applications or services which use the Relying Party Suite (RPS) or FrontPage Remote Procedure Call (FPRPC) will to perform browser-based authentication to perform open operations on Office files will no longer be able to do so. As expected, this is primarily being done to improve the cybersecurity posture of various services. Microsoft states that RPS can be brute-forced and phished with relative ease as it is fairly outdated. Similarly, FPRPC is typically used for remote web page authoring and it is susceptible to exploitation through various vulnerabilities too. As such, both of these protocols will be disabled by default starting from mid-July 2025, with the rollout of this change targeting completion by August 2025. The Redmond tech giant will update the protocol baseline by default without mandating any licensing changes for customers. In addition, once these modifications are rolled out, Microsoft 365 will require admin consent to get third-party access to files and sites. IT admins can view the guidance available here to configure admin consent workflows. Microsoft says that these changes align with the principles of its Secure Future Initiative (SFI). Earlier today, it announced the rollout of improved security defaults for Windows 365 citing the same reasons too.
    • It does and it can... I took an i3 board and upgraded it to my FX8350... no issues, just put in new drivers over the top that Windows didn't. Not the issue for me, (though I eventually did do a new install from 23H2 to 24H2)... I was on 22H2 at the time. The issue is activation. You may get hit with having to activate again.
  • 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
      705
    2. 2
      ATLien_0
      283
    3. 3
      Michael Scrip
      217
    4. 4
      +FloatingFatMan
      195
    5. 5
      Steven P.
      130
  • Tell a friend

    Love Neowin? Tell a friend!