I would actually do a couple of things different, and hopefully you're early enough in your project where you can accomplish this.
First I would not mix areas of the project that can only be accessed by Authorized users, with areas that should be view only. So beyond just locking down an action with the [Authorize] attribute, I'd split up concerns and responsibilities.
However, if you cannot accomplish this I still would not suggest putting all that logic into one action. It will make it more difficult to maintain the project down the road. So split that up. I'd suggest creating two actions. As such:
namespace My.Sample
{
/// <summary>
/// Settings controller used to maintain settings stuff
/// </summary>
public class SettingsController : Controller
{
[Authorize]
public ActionResult EditSettings()
{
return View();
}
public ActionResult ViewSettings()
{
return View();
}
}
}
If your concern is that you will duplicate HTML markup between the two Actions, I'd say don't worry about that so much. It's much more likely that those two views will start to differ drastically as time goes on and then you'll have to wonder how you can maintain that as one, and you'll end up with a huge cshmtl file. Split it up, it will make life much easier later on.
You're probably not looking for a theological answer, but... you should read the following:
https://softwareengineering.stackexchange.com/questions/73065/what-are-dry-kiss-solid-etc-classified-as
If you're still convinced on going the current direction, you can return a different view from an action and pass in a different model. As such:
[Authorize]
public ActionResult EditSettings()
{
var myModel = Services.SettingsService.GetSettings();
return View("ViewSettings", myModel);
}
So, both actions point to one view, one is authorized and one is not. The model passed in can then reflect different states, etc. Your Razor markup can do whatever needs to be done based on that. I still would not recommend doing things this way though, separate those Actions.