0

I am not sure what is going on here.

I have an action method that is called in a jquery script that I have...

                    ondblClickRow: function (id) {
                        debugger;
                        var dummyURL ='@Url.Action("EditEncounter", "EditEncounter", new { encounterId = 0, popId = (int)TempData["POPULATIONID"] })';
                        var path = dummyURL.replace("-2", id);
                        document.location.href = path;
                        //new { encounterId = temp.EncounterId, popId = (int)TempData["POPULATIONID"] }'
                    }

for some reason when I attempt to navigate to this page via this route using chrome I get this exception:

The parameters dictionary contains a null entry for parameter 'popId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult EditEncounter(Int32, Int32)' in 'FocusedReadMissionsRedux.Controllers.EditEncounterController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

But in IE, I call the action method and I navigate to the appropriate page without incident. I must be missing something?

UPDATED I noticed that I was getting this query string...

encounterId=2245&popId=2

Notice thte '&' and the 'amp;'. I am thinking that my route is not being set up correctly. I will try a couple of things and let you gents know what happens.

CONFIRMED

this is the route I have in internet explorer

encounterId=2245&popId=2

And it works. I just need to figure out why this happens for this particular request.

UPDATE

Visual studio is not updating the cshtml files that are generated when I attempt to debug my program. Anybody every experience this and how to get by it?

SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
  • And what do you see in the `Network` tab of the Chrome developer toolbar? What url is being requested? Is it the correct one? Also when you inspect the HTML of the page what's the value of `dummyURL` in the markup. And one final question: what's with the `dummyURL.replace("-2", id)` line? Did you log the value of this `id` variable inside the method? Also you seem to be using TempData over there as you know it can be evicted if an intermediary request that is reading from it has been made. This could for example be an AJAX request. – Darin Dimitrov Jan 14 '13 at 21:38
  • I made sure the tempdata field was hydrated. That line is so I can get an accurate route to navigate to after a certain event is triggered. I will check the html traffic using chrome. – SoftwareSavant Jan 15 '13 at 02:02

2 Answers2

1

I had a similar problem, but was able to resolve that by enclosing my Url.Action inside of a Html.Raw which got rid of the amp; as per this solution Hope someone finds help with this.

Community
  • 1
  • 1
Purusartha
  • 992
  • 4
  • 19
  • 33
0

Have you tried setting your popId to a nullable type? It sounds like it doesn't like your optional parameter being an integer and not a nullable integer. Of course I can't see your Controller and View but this is what the error message is telling me. See below.

Add a int? instead of int

So your ViewResult will need to have nullable parameters in your controller:

public ViewResult EditEncounter(int? encounterId, int? popId)

UPDATE: After further discussion it appears that Chrome is not filling or approving of your TempData object while IE is. Maybe post some more information about this process.

zombiehugs
  • 717
  • 3
  • 10
  • 1
    How would this explain the *IE's working thingy*? How would this solve the problem? Yeah, he would probably not get an exception but he would get null inside the controller action which I suppose is not what's desired here. – Darin Dimitrov Jan 14 '13 at 21:40
  • I would imagine what is happening is that IE is properly filling your `TempData` object while Chrome is not. Hence the issue with it being null, when it gets to your `EditEncounter` method it sees the parameters are required and not `nullable`. Maybe you can post more code to see how and where `TempData` is getting populated and what methods are being used. Possibly there is something there that Chrome doesn't like. – zombiehugs Jan 14 '13 at 21:43
  • 1
    `TempData` is a server side variable. It's not the browser that is filling it. – Darin Dimitrov Jan 14 '13 at 21:43
  • Can you post the code? I imagine if you dumped `TempData` to the screen on Chrome it would return `null` information while IE would obviously contain the object data. – zombiehugs Jan 14 '13 at 21:44
  • If TempData didn't contain a value he would get an InvalidCastException when rendering the view because he is casting it to `(int)`. This doesn't look like being the case here. Obviously it would help if the OP debugged his code a little bit and provided more information so that we don't have to be guessing here. – Darin Dimitrov Jan 14 '13 at 21:46
  • Good call. For a second I thought you were OP. Sorry about that. A typo from above made it sound like you were the guy, after double checking I realize you aren't sorry for talking to you as poster. – zombiehugs Jan 14 '13 at 21:49
  • Temp Data works in every other instance with Chrome. I am not certain it is at the root of the problem here. I just noticed when looking at the URL that I get this... encounterId=2245&popId=2 Notice the and and the amp; I am thinking my route isn't being generate correctly, therefore It thinks that I am sending in a null value. I will update my post and try some things. I will let you guys know. – SoftwareSavant Jan 15 '13 at 12:22