0

I am trying to figure out if I can do this, and how..

I have an action result defined this way :

public virtual JsonResult Created(string tableName, object where)
    {
       ....some code
    }

I am using T4MVC and I am trying to call the action result like this:

MVC.MyController.Created("MyTable", new { Name = "Matt", Age = 11})

But in the controller the where parameter has a type of object {string[]} and it has only one entry and that one looks like this:

where[0]="{ Name = "Matt", Age = 11 }"

Is there a way to get the where parameter as an anonymous type in MyController?

Update:

The Created method is called every few seconds to look in the database and return true if a certain row is created.This is the method that calls the Created method:

public virtual ActionResult WaitingForUpdate(JsonResult pollAction, string    redirectToOnSave = null)
    {
        return View("CommandSentPartial", new CommandSentModel
                                              {
                                                  Message = "Waiting for update",
                                                  PollAction = pollAction,
                                                  RedirectTo = redirectToOnSave
                                              });
    }

and then I am calling

WaitingForUpdate(MVC.MyController.Created("MyTable", new { Name = "Matt", Age = 11}))
Oana Marina
  • 277
  • 3
  • 19
  • T4MVC aside, how would you do this in plain MVC? Please see section 1.1. in https://t4mvc.codeplex.com/documentation – David Ebbo Jan 16 '14 at 01:53
  • Thanks for the idea! I tried doing it like this : new MyController().Created("MyTable", new { Name = "Matt", Age = 11}) and it worked just fine, the where parameter was an anonymous type in the controller, so I think is a T4MVC problem... – Oana Marina Jan 16 '14 at 15:08
  • What you tried is different, as you're making a direct method call. With both T4MVC and straight MVC, you end up creating a link (a URL), that when clicked, invokes your action. Can you show a little bit more of your code? How are you using what the method call returns? e.g. are you calling `Html.ActionLink()`? – David Ebbo Jan 16 '14 at 17:31
  • The Created method is called every few seconds to look in the database and return true if a certain row is created. – Oana Marina Jan 16 '14 at 18:06
  • Ref: http://t4mvc.codeplex.com/workitem/37 – David Ebbo Jan 16 '14 at 23:03

1 Answers1

1

If your goal is to call the Create method directly, then you should not be using T4MVC, but simply make a direct method call to it. T4MVC is to help generate links that later call into the Action via MVC routing. Can you just call

this.Created(...)

directly?

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • I don't think so. MyController is based on a few inputs that are provided through dependency injection, and using it directly means I have to provide those inputs... – Oana Marina Jan 17 '14 at 14:01