0

I have read this link: https://www.future-processing.pl/blog/view-code-reuse-techniques-in-asp-net-mvc/

I can not use any of those helper ways...

I have to show on multiple mvc sites this string:

1612-1

That is an inquiry number: 16 is the day of month, 12 the month of year and 1 is the database id. I am sure that will not be the final impl but for now we take it as given.

public class MyViewModel
    {
        public string City { get; set; }
        public string PostalCode { get; set; }
        public List<string> ActionItemDescriptions { get; set; }
        public string InquiryNumber { get; set; }
    }

Where would you create the InquiryNumber?

If I put it inside the razor view I cant reuse it.

1
  • can you show your view ? Commented Dec 16, 2015 at 15:43

2 Answers 2

1

Seems business logic to me , so it belongs in the business layer.

Then, from within your controller you:

  • call the business component which returns the inquiry number
  • store the number in your view model
  • pass the view model to the view.
Sign up to request clarification or add additional context in comments.

12 Comments

busines logic? To me that is presentation logic.
Calculating an inquiry number is no presentation logic at all. Presentation logic is about presenting data to the user, and everything about UI manipulation, but not calculating it. It's something you probably need outside the UI also, for example in background processes etc.
Anyway, if according to you this is not business logic, the principle stays the same: you have it calculated by a component which is called from the controller.
and what is this component named in the mvc architecture?
It's not overhead, it's best practice. But by all means, feel free to do whatever you want :)
|
0

One way you could get an inquiry number, without using a helper, is this:

In a controller, have the following action method:

public ActionResult GetInquiryNumber()
{
    // TODO : The code to get the inquiry number.
    return Content("1612-1");
}

You can then call that method in any view you like, using the following:

@{ Html.RenderAction("GetInquiryNumber", "Home"); }

Obviously you will need to come up with your own method, and controller, names.

This isn't the ideal way of passing data to a view (using a viewmodel is preferable), but the above approach is an option to you.

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.