return new EmptyResult() VS return NULL

You can return null. MVC will detect that and return an EmptyResult. MSDN: EmptyResult represents a result that doesn’t do anything, like a controller action returning null Source code of MVC. public class EmptyResult : ActionResult { private static readonly EmptyResult _singleton = new EmptyResult(); internal static EmptyResult Instance { get { return _singleton; } … Read more

Rails: Multi-submit buttons in one Form

This was covered in Railscast episode 38. Using the params hash to detect which button was clicked is the correct approach: View: <%= submit_tag ‘Create’ %> <%= submit_tag ‘Create and Add Another’, name: ‘create_and_add’ %> Controller: if params[:create_and_add] # Redirect to new form, for example. else # Redirect to show the newly created record, for … Read more

How do you use Func and Action when designing applications?

They’re also handy for refactoring switch statements. Take the following (albeit simple) example: public void Move(int distance, Direction direction) { switch (direction) { case Direction.Up : Position.Y += distance; break; case Direction.Down: Position.Y -= distance; break; case Direction.Left: Position.X -= distance; break; case Direction.Right: Position.X += distance; break; } } With an Action delegate, you … Read more

Creating delegates manually vs using Action/Func delegates

The advent of Action and Func family of delegates has rendered custom delegates less used, but the latter still finds uses. Advantages of custom delegates include: As others have pointed, conveys intent clearly unlike generic Action and Func (Patrik has a very good point about meaningful parameter names). You can specify ref/out parameters unlike the … Read more

How can I pass a parameter in Action?

If you know what parameter you want to pass, take a Action<T> for the type. Example: void LoopMethod (Action<int> code, int count) { for (int i = 0; i < count; i++) { code(i); } } If you want the parameter to be passed to your method, make the method generic: void LoopMethod<T> (Action<T> code, … Read more

Web API Routing – api/{controller}/{action}/{id} “dysfunctions” api/{controller}/{id}

The route engine uses the same sequence as you add rules into it. Once it gets the first matched rule, it will stop checking other rules and take this to search for controller and action. So, you should: Put your specific rules ahead of your general rules(like default), which means use RouteTable.Routes.MapHttpRoute to map “WithActionApi” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)