Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controller Functions 1

Status
Not open for further replies.

ca8msm

Programmer
May 9, 2002
11,327
GB
In what scenarios would you have a controller function that doesn't have an associated View? For example, it's possible in a controller to return anything (as opposed to what I would class as the default - an ActionResult for a View) so you could have:
Code:
        Function GetDate() As DateTime
            Return DateTime.Now.ToString
        End Function
And any call to the function would result in the current date being written out in the browser. However, as no View is involved, there obviously isn't any formatting or anything like that rendered so I'm wondering where it's best use is.

I've used MVC In our latest project to get a bit more up to speed on it, but I think all of our functions seem to return a View and so I just want to make sure I'm not missing a trick somewhere.

Thanks,

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Hi,

you only need to return a view when you want to render a view. Nothing stops you to have controller actions that don't render views.

I have many pages that get additional data via AJAX:
In that case I let my controller return data JSON format that can be consumed by the javascript on the client side.

small sample:
Code:
[CheckRole(roleType.OpenTime, aclType.aclRead)]
        public JsonResult GetSchedulesConfiguration(string id, string groupId)
        {
            var configuration = schedulePresentationService.GetSchedulesConfiguration(ControllerContext);
            return Json(configuration, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post), CheckRole(roleType.OpenTime, aclType.aclRead)]
        public JsonResult GetSchedules(string groupId, JqGridPostData postdata)
        {
            return Json(schedulePresentationService.Schedules(postdata).JsonData);
        }

        [AcceptVerbs(HttpVerbs.Post), CheckRole(roleType.OpenTime, aclType.aclRead)]
        public JsonResult GetScheduleDays(string id)
        {
            Double scheduleId = -1;
            Double.TryParse(id, out scheduleId);
            return Json(schedulePresentationService.ScheduleDays((int)scheduleId));
        }

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thanks, the download file example is one I hadn't thought about.

I think I'm convinced that for now I've taken the correct approach with what I have so far and I'll add the JSON method calls in as additional functionality now that I have the application functionality working correctly.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top