question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ViewBag analyzer

See original GitHub issue

I would like to suggest a new analyzer. An analyzer to point out the usage of ViewBag and replace it with an model

Before:

MyController.cs


ViewBag.Message = "Hello World";

After:

MyModel.cs


public string Message { get; set; }

MyController.cs



model.Message = "Hello World;"

Why I think this is useful? ViewBag is a dynamic property and you will only catch errors at runtime making your code error prone.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JohanLarssoncommented, Aug 31, 2019

If this is for AspNetCore there is the official analyzer

There is also AspNetCoreAnalyzers.

0reactions
sharwellcommented, Sep 5, 2019

@kidchenko It probably wouldn’t make sense for StyleCop Analyzers, but would make sense for one of the other projects linked above. If you are interested in contributing, I would suggest opening an issue on those to check if the project would use it. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

ViewBag in ASP.NET MVC
The ViewBag in ASP.NET MVC is used to transfer temporary data (which is not included in the model) from the controller to the...
Read more >
Analyzing ASP.NET MVC Projects with Roslyn
I am currently working on a static source code analyzer for ASP. ... however in MVC projects, it is common to use ViewBag...
Read more >
Analyzers For ASP.NET Core In .NET 6
Analyzers are tools that analyze source code and provide feedback to developers in the form of warnings and suggestions for improvement. In ASP....
Read more >
viewdata and viewbag in asp net mvc - YouTube
viewdata and viewbag in asp net mvc. ... Excel Data Analysis Made Easy: Transform Your Data Into Insights. IBU Data Simplified New 592...
Read more >
Rule S5770: View data dictionaries should be replaced by models
An analyzer to point out the usage of ViewBag and replace it with an model Expected behavior MyModel.cs public string Message { get;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found