0

I need to get the resource data on js file. so I want to transfer the resource data from controler action to js file by ajax callback. How to do this?
I'm working in asp.net mvc 5

1 Answer 1

1

I'm do it's so:
controller Action:

 [HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
public ActionResult GetCultureResource()
{
      ResourceSet resourceSet = 
  Resources.Resources.ResourceManager.GetResourceSet(new  System.Globalization.CultureInfo(cultureName), true, true);
   var dicResource= resourceSet.Cast<DictionaryEntry>()
                  .ToDictionary(x => x.Key.ToString(),
                                x => x.Value.ToString());

   var jsonString = JsonConvert.SerializeObject(dicResource);

  return Json(new { resource = jsonString});

 }

javascript fanction:

function SetCultureResource() {
    $.ajax({
        type: "POST",
        url: "/ControllerName/GetCultureResource",
        dataType: "json",
        success: function (data) {
            var obj = jQuery.parseJSON(data.resource);
        //do somthing as this with Resource
        //alert(Resource.BeforLogOut);
        },
        error: function (data) {

        }
    });
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.