I have a few .cshtml files which contains the design of a form in Visual Studio.
As I am debugging it locally, I do not have access to the database. Therefore, when I click on View in Browser, I will get errors.
May I know are there any others ways that can I preview the design of the form?
Thank you.
Visual Studio doesn't have a visual designer for razor pages like the one available for Web Forms. You could try opening the file with the "HTML (Web Forms) Editor" by using the option "Open with..." in that context menu, but I don't think it will render anything useful.
Your default option would be "View Markup", and you must interpret the layout of your form by looking at the HTML elements composing it.
I have two possible suggestions:
Create a local database with the same basic schema and change the connection to it for debugging. This requires minimal changes to the existing code and is my preferred method.
Alternatively, create some dummy data to display on the page in place of what would be filled from the database. Probably a slightly quicker solution than the first one, but potentially means a lot of code edits.
Related
I work on reality big project. And sometimes i get the need to search for some specific keyword inside A single c# file that has many calls of other functions from other c# file.
So i want to know if there is any easy way that could search for give phrase or keyword inside the current file and inside all the functions that my current file calls to. But not in the entire solution or inside the whole project.
For inside the file that's Ctrl+F.
Otherwise Code Search in VS2022 is very fast. Normally it's bound to Ctrl+T.
Introducing a New Way to Search Your Code and Visual Studio Features
Code search in Visual Studio 2022 is about to get much faster).
There also are the Go To options in the context menu that could help:
Finally, at the top of the editor window you can switch between classes and properties/methods.
BTW. You can address the large solution problem by splitting the codbase into multiple smaller solutions that only include parts of the overall code. This has some drawbacks, but overall it works very well in my experience.
I have modified my question after the comment which refers to article.
I have a c# Win forms app which contains some forms and dialog boxes/message boxes for user interaction.
I want to localize it to a set of languages.
Most forms are created through the forms designer and the text/strings are set via the properties
Strings for message boxes and other runtime messages come from the code.
I have read the article here
http://msdn.microsoft.com/en-us/library/y99d1cd3(v=vs.71).aspx
Which points to 2 approaches,
First is to have Visual Studio create resouece files for you - this is done for forms designer gernerated code
The second is to manually add resource files and access them code using GetString("strMessage") method
The problem I have in my mind is for desingner generated code I have to use first approch in which VS will create resource files by itself.
To localize my run time messages and mssage boxes I have to use the second approach which means I have to manually add resource files.
I will end up in two sets of resources files for each language. Can I not use just one method and have both form of strings localized in one place ?
Thanks,
Unfortunately you can't (easily) have your cake and eat it too. It's just how MSFT designed things. You can't add message strings to the code-behind ".resx" files generated by the VS forms designer since those ".resx" files will be re-generated by VS any time you make changes to them (overwriting your message strings). VS even warns you about this if you try to add your own resources to these files (using the ".resx" editor in VS). And the converse isn't true either, i.e., you can't add the code-behind ".resx" resources to your manually created ".resx" files (without enormous difficulties). The situation really isn't that bad though. It's been done for years this way and it works. While I would personally prefer a central repository for all resources, every system has its pros and cons. BTW, you should use "strongly typed" resources for your message strings and any other resources in your ".resx" files (the ones you manually add yourself). Don't use "GetString()" IOW (or whatever other function you might find). Strongly typed resources are much easier. Google for the details and after learning how to use them (not hard), also search for the Strongly Typed Resource Generator by Dmytro Kryvko (a very useful tool for VS that improves things even more).
There is nothing stopping you using a combination of both techniques. Go through step 1 to create all of the language resource files, and then add your own strings to those files.
When showing the open file dialog, I want to show up the "App,lication Links" category in the left side pane on Vista/7. Visual Studio does that too when opening project files.
How can I do this with a standard OpenFileDialog-Object in C#? I am using WPF by the way, but I don't think that matters in this case.
You need to use FileDialog.CustomPlaces. That MSDN link contains some sample code to get you going. Ultimately this is wrapping the native functionality exposed by IFileDialog::AddPlace.
I'm trying to switch my custom cms written in php into .net c#. I was thinking to use cms as a learning project. I'm going to use C#, NHibernate ORM layer, mssql, mvc3 and jquery.
I'm aware there are plenty of commercials or open source cms, but still I'm going to spend some of my free time trying to learn new technology working on project like this.
So, is there anyone out there who is willing to share some ideas on creating cms domain model, usefull link, ideas, etc.
Thanks
A really basic CMS consist of 3 elements:
one database table to hold your "pages". The table structure is "name" and "content"
a route to transform requests of type /cms/pagename to a fixed controller, the method called cms and pagename as a parameter
a embeddable html editor
Now, there are two ways your "page" can be invoked. It is either create mode or view/edit mode.
In "create" mode, the page is requested but it is not in the database yet (e.g. cms/announcement1). In this mode you create a view consisting of a html editor and upon submit, you persist the page to the database.
In "view" mode, the page is requested and is IS in the database. You perform any necessary rewriting (for example you rewrite internal links of the form [cms/pagename] to a fully routable http address) and render the content.
If the user is authorized to edit the page, you also show a "edit" button which then invokes the html editor with the page loaded and ready to be edited.
And that's it.
There are tons of additional elements (caching, different built-in page types, embedding images, youtubes, preformatted texts) etc. but all of them are optional and you can introduce new features when you have the core already implemented.
Once I wrote a simple CMS following the structure above, it was a part of a bigger solution and till now it's been sucesfully deployed several hundred times. An advantage of a custom CMS is that it can be really simple and easily maintanable.
I have a C# project and some code pages have few thousand lines of code. I really like the idea of nodes in the code editor. I use it a lot and create many regions. But every time I open the project, all the nodes are expanded and I have to minimize them manually. It gets really annoying.
I have not found any help about this on internet nor in the options of VS. There must be a setting somewhere.
In the Options dialog onder Text Editor --> C# --> Advanced, there is an option "Enter outlining mode when files open". This should be checked.
In the IDE, from the Tools menu click Options. Alter default Outlining using
TextEditor->C#->Formatting->Advanced
There is a checkbox here you can use to set defaults for Outlining. This is VC# 10 Express but similar in other versions.
If you try the suggested change, you may be disappointed. According to this C# PM, who's responding to a similar complaint:
It is a bit confusing, but the
behavior you're seeing is intended.
The feedback that we received with VS
2003 was that we should persist the
outlining state of source files after
they have been closed and then
reopened. The option in Tools |
Option now effectively means what the
default behavior should be for a file
that you have never opened before. It
has no effect on files that you have
opened previously, since those files
already have a persisted outlining
state.
I don't want be a smart ass here, but often if you have that huge code in one file, you have more than one logical unit and might be able to (ans should) split it. (Single Responsibility Principle).
For my share, I don't like the regions because they are hiding code and I prefer to see all of it.