controller

Return Multiple Objects Using ASP.NET MVC'S JsonResult Class

让人想犯罪 __ 提交于 2019-12-03 15:45:35
Is it possible to Multiple Objects Using ASP.NET MVC'S JsonResult Class.... Here is a controller method which returns json object of my records but i also want to pass the count value.... var materials = consRepository.FindAllMaterials().AsQueryable(); var count = materials.Count(); var results = new PagedList<MaterialsObj>(materials, currentPage-1, pageSize); return Json(results); How to return count along with the results from asp.net mvc controller.... How about creating an anonymous type and JSON'ing that? e.g. var resultCount = results.Count; var genericResult = new { Count = resultCount,

NEW T4 Controller Template in MVC3

我与影子孤独终老i 提交于 2019-12-03 15:23:56
As you know to create new t4 templates in MVC, need to add CodeTemplates folder to project. There are two main subfolders 1- AddController , 2- AddView I always use AddView folder to add new templates to generate custom views, know I need new template to generate controllers, but when I add new tt file to AddController folder, there is no any new option in templates of new controller, there is always 3 options: So how can I add new option to Add Controller window to use my custom Controller Template? Or if I try wrong way, what is your suggestion to use Template to generate controllers? It

responding with multiple JSON renders. (Ruby/Rails)

被刻印的时光 ゝ 提交于 2019-12-03 15:00:51
问题 This is a relatively simple one and I'm pretty sure its just syntax. Im trying to render multiple objects as json as a response in a controller. So something like this: def info @allWebsites = Website.all @allPages = Page.all @allElementTypes = ElementType.all @allElementData = ElementData.all respond_to do |format| format.json{render :json => @allWebsites} format.json{render :json =>@allPages} format.json{render :json =>@allElementTypes} format.json{render :json =>@allElementData} end end

How can I test an event of a MVC controller

我只是一个虾纸丫 提交于 2019-12-03 14:38:03
I want to test the OnException , OnActionExecuted event of an MVC controller. If I use mock like this: var httpContext = MockRepository.GenerateMock<HttpContextBase>(); var request = MockRepository.GenerateMock<HttpRequestBase>(); httpContext.Expect(c => c.Request).Return(request).Repeat.AtLeastOnce(); request.Expect(r => r.IsAuthenticated ).Return(true).Repeat.AtLeastOnce(); var controller = new MyController() ; controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller); var result = controller.Execute() as ViewResult; …the action method is executing, but

Get checkbox values in controller mvc 4

两盒软妹~` 提交于 2019-12-03 13:56:45
问题 I am trying to retrieve the checked checkbox value from a checkbox list without any success , below is the code which i have tried: Model [DisplayName("Gender")] public IList<SelectListItem> Gender { get; set; } Controller public ActionResult Index() { AssociateFormViewModel objStudentModel = new AssociateFormViewModel(); List<SelectListItem> genderNames = new List<SelectListItem>(); genderNames.Add(new SelectListItem { Text = "Male", Value = "1" }); genderNames.Add(new SelectListItem { Text

Returning from rails controller

半世苍凉 提交于 2019-12-03 13:48:56
问题 Here's a beginner rails question... After I do: format.xml { head: ok} How do I return from the controller endpoint without showing the view? If I drop off the end of the function at this point, I get what I expect, but if I call 'return', I end up in the view (or in my case in a missing view template). I can code up lots of if/else etc., but it would be nice to early out from the function without ending up in a view template. I've searched around and can't figure out what the obvious answer

ExtJS 4.1 Call One Controller From Another

假如想象 提交于 2019-12-03 12:55:57
问题 Note: I'm a total ignoramus regarding javascript. I've broken my ExtJS 4.1 MVC app out into several controllers like: /app/controller/Auth | |Quiz | |Result | |Blah... |model/... I want to respond to an "event", not a DOM Event , rather a Ext.form.action.Submit.success event by calling functions in both my Auth and Quiz controllers. The summarized code for the first part is here: // File: app/controller/Auth.js attemptLogin : function() { var form = Ext.ComponentQuery.query('#loginpanel')[0]

Passing local variables to a view from controller

会有一股神秘感。 提交于 2019-12-03 12:39:00
I am not able for some reason to pass local variables to the show view... In my controller i have simply: def show render template: "books/show", :resource => "Some text" end In my view i print the following: <h1>My local variable text: <%= resource %></h1> And i am getting the following message: undefined local variable or method `resource' for #<#<Class:0x00000118ebce90>:0x00000118ec3498> I've tried the following syntaxes in the controller: render template: "books/show", locals: { resource: "Some text" } render template: "books/show", locals: { resource => "Some text" } render template:

Is there a way to have a Codeigniter controller return an image?

梦想与她 提交于 2019-12-03 12:04:30
I was wondering if there was a way for a controller to, instead of returning a string, or a view, return an image (be it JPG, PNG etc). For example, instead of ending with a $this->load->view('folder/special_view.php), I'd like to do something like $this->load->image('images/gorilla.png'), and have it so if my user were to go to that controller they would see an image as if they'd gone to a normal .png or jpeg. Can I set the headers so it expects a different MIME? Example code of this would be fantastic. It would take forever for me to explain why I need this, but it involves bringing a

Spring MockMVC inject mockHttpServletRequest when not in method signature

馋奶兔 提交于 2019-12-03 11:40:30
Given I have inherited some Spring MVC controller code with signature @RequestMapping(value = "/upload", method = RequestMethod.POST) public ModelAndView upload(HttpServletRequest request, HttpServletResponse response) { String remoteAddress = request.getRemotedAddr(); auditService.logAddress(remoteAddress); // do work... return mav; } and I have a Spring MockMvc test that performs the test public void someTest() { mockMvc().perform(fileUpload("/upload").file(FileFactory.stringContent("myFile"))); // do work... verify(auditService.logAddress("123456")); } I need to set the remote address to