Angularjs – Pass argument to directive

You can pass arguments to your custom directive as you do with the builtin Angular-directives – by specifying an attribute on the directive-element: angular.element(document.getElementById(‘wrapper’)) .append(‘<directive-name title=”title2″></directive-name>’); What you need to do is define the scope (including the argument(s)/parameter(s)) in the factory function of your directive. In below example the directive takes a title-parameter. You can … Read more

Why is it that “No HTTP resource was found that matches the request URI” here?

Your problems have nothing to do with POST/GET but only with how you specify parameters in RouteAttribute. To ensure this, I added support for both verbs in my samples. Let’s go back to two very simple working examples. [Route(“api/deliveryitems/{anyString}”)] [HttpGet, HttpPost] public HttpResponseMessage GetDeliveryItemsOne(string anyString) { return Request.CreateResponse<string>(HttpStatusCode.OK, anyString); } And [Route(“api/deliveryitems”)] [HttpGet, HttpPost] public … Read more

Fat models, skinny controllers and the MVC design pattern

It’s a bit tough to give you the “right” answers, since some of them deal with the specifics of the framework (regardless of the ones you are working with). At least in terms of CakePHP: Yes Anything that deals with data or data manipulation should be in a model. In terms of CakePHP what about … Read more

Can we pass model as a parameter in RedirectToAction?

Using TempData Represents a set of data that persists only from one request to the next [HttpPost] public ActionResult FillStudent(Student student1) { TempData[“student”]= new Student(); return RedirectToAction(“GetStudent”,”Student”); } [HttpGet] public ActionResult GetStudent(Student passedStd) { Student std=(Student)TempData[“student”]; return View(); } Alternative way Pass the data using Query string return RedirectToAction(“GetStudent”,”Student”, new {Name=”John”, Class=”clsz”}); This will generate … Read more

How to access plain json body in Spring rest controller?

Best way I found until now is: @RequestMapping(value = “/greeting”, method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) @ResponseBody public String greetingJson(HttpEntity<String> httpEntity) { String json = httpEntity.getBody(); // json contains the plain json string Let me know if there are other alternatives.

In Spring MVC, how can I set the mime type header when using @ResponseBody

Use ResponseEntity instead of ResponseBody. This way you have access to the response headers and you can set the appropiate content type. According to the Spring docs: The HttpEntity is similar to @RequestBody and @ResponseBody. Besides getting access to the request and response body, HttpEntity (and the response-specific subclass ResponseEntity) also allows access to the … Read more

asp.net mvc3: How to return raw html to view?

There’s no much point in doing that, because View should be generating html, not the controller. But anyways, you could use Controller.Content method, which gives you ability to specify result html, also content-type and encoding public ActionResult Index() { return Content(“<html></html>”); } Or you could use the trick built in asp.net-mvc framework – make the … Read more

Why we shouldn’t make a Spring MVC controller @Transactional?

TLDR: this is because only the service layer in the application has the logic needed to identify the scope of a database/business transaction. The controller and persistence layer by design can’t/shouldn’t know the scope of a transaction. The controller can be made @Transactional, but indeed it’s a common recommendation to only make the service layer … Read more