Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have already added system.web.mvc reference and system.web.mvc.dll in bin ..But when i am using following code in global.asax it is giving above error in MVC2

protected void Application_Start()<br />
       {<br />
           AreaRegistration.RegisterAllAreas();<br />
           RegisterRoutes(RouteTable.Routes);<br />
           ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());<br />
       }

Plz help what i am missing???.tthis JsonValueProviderFactory() is giving error
Posted
Updated 10-Feb-14 20:17pm
v2

1 solution

Please try is as below.

C#
protected void Application_Start()
        {
          AreaRegistration.RegisterAllAreas();

          RegisterGlobalFilters(GlobalFilters.Filters);
          RegisterRoutes(RouteTable.Routes);

         //Remove and JsonValueProviderFactory and add JsonDotNetValueProviderFactory
            ValueProviderFactories.Factories.Remove(ValueProviderFactories.Factories.OfType<JsonValueProviderFactory>().FirstOrDefault());

      ValueProviderFactories.Factories.Add(new JsonDotNetValueProviderFactory());
        }



Please read the below mentioned article to get more details about how to configure JsonValueProviderFactory using Json.Net.

JsonValueProviderFactory using Json.Net

UPDATE

This is a sample which I extracted from my project.Please change it according to your situation.

JS

$.ajax({
                               url: "/PetBooking/GetSelectedCategoryTypeServices",
                               dataType: 'json',
                               data: { providerKey: '<%:Model.Provider.Key%>', serviceCategoryTypeId: serviceCategoryTypeId },
                               success: function (data) {

                                   $("#ddlService").fillSelect(data);
                                   whenOnlyService();
                                   $("#ddlService").sb("refresh"); //for refresh after Ajax call
                                   $('#ddlService').trigger('change');
                                   HideLoader();
                               }
                           });


Action method

SQL
[HttpGet]
   public JsonResult GetSelectedCategoryTypeServices(string providerKey, string serviceCategoryTypeId)
   {

       return Json(defaultItems.Union(items), JsonRequestBehavior.AllowGet);
   }
 
Share this answer
 
v2
Comments
Member 10435696 11-Feb-14 4:37am    
I am getting the same error with this also...It gives red mark on JsonDotNetValueProviderFactory()..
Sampath Lokuge 11-Feb-14 4:40am    
Please follow the steps of the above article which I shared with you.
Member 10435696 11-Feb-14 5:17am    
I have followed the steps...Getting error in JsonDotNetValueProviderFactory class->
Unexpected character encountered while parsing value: U. Path '', line 0, position 0.

Getting Error in This Line-

return String.IsNullOrEmpty(bodyText) ? null : new DictionaryValueProvider<object>(JsonConvert.DeserializeObject<expandoobject>(bodyText, new ExpandoObjectConverter()) ,
CultureInfo.CurrentCulture);
Sampath Lokuge 11-Feb-14 5:20am    
Yep,then your problem with the 'bodyText' value.May be there is something which doesn't support by the json.net.Please check that.
Member 10435696 11-Feb-14 6:12am    
My view -><input type="text" name="USER_NAME" id="USER_NAME" />

<input type="text" name="MOBILE_NO" id="MOBILE_NO" />

<input type="text" name="EMAIL_ID" id="EMAIL_ID"/>

<input type="button" id="submitButton" value="Save"/>



Now on submit button->
<script type="text/javascript">
$(function () {
var submitButton = $("#submitButton");
// var infoForm = $("#infoForm");
// alert(infoForm);
// Attach event handler to submit button
submitButton.click(function () {
SubmitInfo();
});
});
</script>



<script type="text/javascript">
function SubmitInfo() {
alert("in fun");
$.ajax({
url: "User/Index",
type: 'post',
datatype:'json',
contentType: "application/json;charset=utf-8",

data: "{'USER_NAME':'" + escape(USER_NAME.val()) + "', 'MOBILE_NO':'" + escape(MOBILE_NO.val()) + "' ,'EMAIL_ID':'" + escape(EMAIL_ID.val()) + "'}",

success: function (data) {
alert("fff");
if (data) {
// Clear the input tags

formContainer.find("input[type='text']").each(function (i, element) {
$(this).val('');
});
}
alert("giii");
alert(data.Message);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
</script>

Plz help me to resolve this issue..Does mvc2 support json datatype.Bec when i use 'data' as mentioned above..It dosnt rediect to above url

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900