0

In webforms, we do things like:

<%# CallSomefunctions(Eval("CustId")) %>

This function is present in asp.cs which can format our data and return appropriate string. How can we do the same in asp.net mvc since we do not have any concept of code behind?

1 Answer 1

1

The short answer is: You don't. Doing this violates the principles of MVC. The responsibility of your .aspx page it to convert a model (some .NET object) into something you can present to the user and nothing else. Having it execute code violates this one-responsibility principle.

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

2 Comments

So what are the options? Say, I have a list of customers index method in controller and I want to display age from the birthdate. How do I do that? If I am correct you mean to say create a partial class of the model and then do Math stuff there. Am I correct?
If I am understanding you correctly: Yes. The controller returns an IEnumerable<Customer> (or whatever), sorted in whatever way you want. The view then transforms that collection of objects into HTML.

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.