Skip to main content
edited tags
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Naming of method that returns Returning a viewmodel

added 3 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

In my ASP.NET MVC code, I like to use controller service classes for my controllers. These service classes contain methods for retrieving viewmodel objects. 

Here is an example controller snippet:

public SubscriptionsController(ISubscriptionsControllerService service)
{
    _service = service;
}

public ActionResult Index(Guid id)
{
    return View("Subscriptions", _service.GetSubscriptionsViewModelOnGet(id));
}

[HttpPost]
public ActionResult Index(SubscriptionsViewModel viewModel)
{
    _service.SaveSubscriptions(viewModel);

    return View("Subscriptions", _service.GetSubscriptionsViewModelOnPost(viewModel));
}

As you can see, I have a method for retrieving the subscriptions viewmodel on a GET request, as well as the equivalent for a POST request.

The POST method takes in an existing viewmodel object and updates any relevant data e.g. a list of subscription items, that need to be refreshed before passing back to the view.

My question is whether the naming of the methods (GetSubscriptionsViewModelOnGet() and GetSubscriptionsViewModelOnPost()) makes sense. They seem OK to me, but I'm interested in other people's views.

In my ASP.NET MVC code, I like to use controller service classes for my controllers. These service classes contain methods for retrieving viewmodel objects. Here is an example controller snippet:

public SubscriptionsController(ISubscriptionsControllerService service)
{
    _service = service;
}

public ActionResult Index(Guid id)
{
    return View("Subscriptions", _service.GetSubscriptionsViewModelOnGet(id));
}

[HttpPost]
public ActionResult Index(SubscriptionsViewModel viewModel)
{
    _service.SaveSubscriptions(viewModel);

    return View("Subscriptions", _service.GetSubscriptionsViewModelOnPost(viewModel));
}

As you can see, I have a method for retrieving the subscriptions viewmodel on a GET request, as well as the equivalent for a POST request.

The POST method takes in an existing viewmodel object and updates any relevant data e.g. a list of subscription items, that need to be refreshed before passing back to the view.

My question is whether the naming of the methods (GetSubscriptionsViewModelOnGet() and GetSubscriptionsViewModelOnPost()) makes sense. They seem OK to me, but I'm interested in other people's views.

In my ASP.NET MVC code, I like to use controller service classes for my controllers. These service classes contain methods for retrieving viewmodel objects. 

Here is an example controller snippet:

public SubscriptionsController(ISubscriptionsControllerService service)
{
    _service = service;
}

public ActionResult Index(Guid id)
{
    return View("Subscriptions", _service.GetSubscriptionsViewModelOnGet(id));
}

[HttpPost]
public ActionResult Index(SubscriptionsViewModel viewModel)
{
    _service.SaveSubscriptions(viewModel);

    return View("Subscriptions", _service.GetSubscriptionsViewModelOnPost(viewModel));
}

As you can see, I have a method for retrieving the subscriptions viewmodel on a GET request, as well as the equivalent for a POST request.

The POST method takes in an existing viewmodel object and updates any relevant data e.g. a list of subscription items, that need to be refreshed before passing back to the view.

My question is whether the naming of the methods (GetSubscriptionsViewModelOnGet() and GetSubscriptionsViewModelOnPost()) makes sense. They seem OK to me, but I'm interested in other people's views.

Source Link
Jason Evans
  • 405
  • 3
  • 10

Naming of method that returns a viewmodel

In my ASP.NET MVC code, I like to use controller service classes for my controllers. These service classes contain methods for retrieving viewmodel objects. Here is an example controller snippet:

public SubscriptionsController(ISubscriptionsControllerService service)
{
    _service = service;
}

public ActionResult Index(Guid id)
{
    return View("Subscriptions", _service.GetSubscriptionsViewModelOnGet(id));
}

[HttpPost]
public ActionResult Index(SubscriptionsViewModel viewModel)
{
    _service.SaveSubscriptions(viewModel);

    return View("Subscriptions", _service.GetSubscriptionsViewModelOnPost(viewModel));
}

As you can see, I have a method for retrieving the subscriptions viewmodel on a GET request, as well as the equivalent for a POST request.

The POST method takes in an existing viewmodel object and updates any relevant data e.g. a list of subscription items, that need to be refreshed before passing back to the view.

My question is whether the naming of the methods (GetSubscriptionsViewModelOnGet() and GetSubscriptionsViewModelOnPost()) makes sense. They seem OK to me, but I'm interested in other people's views.