0

I created a Asp.net mvc project on visual studios, In the many folder I get I have a folder called Home that has three .csthml files: about.cshtml, contact.cshtml, and index.cshtml.

I would like to change about.cshtml to blah.cshtml and contact.chstml to lala.cshtml.

I've tried to do it from properties but the name is not changed across other files in the project.

Should I use those files in my project or create another controller?

1
  • 1
    The best practice is to keep your view names and action names the same, but as @user3601887 mentioned you can decorate your action with a different view name. You can also return a view name in your action i.e. return View("lala"); Commented Jun 13, 2015 at 12:59

2 Answers 2

2

click on the file, push F2 and then rename (type in the new name) or right click the file and select rename. Make sure that you are not running the application (which may be the issue).

If you do change the name, the action in the controllers should also probably be updated.

Sign up to request clarification or add additional context in comments.

1 Comment

Also remember to update any JS Ajax calls to match your new controller method name
1

Also, you can rename only view and then set [ViewName()] attribute for the action.

For instance, you renamed about.cshtml to blah.cshtml:

 [ViewName("~/Views/Home/blah.cshtml")]
 public ViewResult About()
 {
    ...
    return View();
 }

However, better keep names the same

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.