0

I am using the following code

function test() { GetAttributesForSelectedControlType('Phone Number'); } function GetAttributesForSelectedControlType(questionType) { alert(questionType); $.ajax({ url: '/Wizards/GetAttributesForSelectedControlType/' + questionType, type: "GET", contentType: "application/json", success: function (result) { alert('success'); } }); } 

PLEASE NOTE: QUESTIONTYPE is a STRING value and not any type..

The issue is that in the controller, I m getting a hit on "GetAttributesForSelectedControlType" function but the parameter value is coming null. I am sending string in questionType. any ideas on this?

9
  • Are you getting correct value in alert? Commented Jun 19, 2013 at 6:46
  • Show us the code from where you are passing the parameter i.e. how you are calling the function. Commented Jun 19, 2013 at 6:47
  • @Amit Yes the value in alert is exactly what i need. Commented Jun 19, 2013 at 6:48
  • Also, the method-signature/route-setup might help. Commented Jun 19, 2013 at 6:48
  • Use this as querystring. then you will get value Commented Jun 19, 2013 at 6:49

3 Answers 3

1
function GetAttributesForSelectedControlType(questionType) { alert(questionType); $.ajax({ url: '/Wizards/GetAttributesForSelectedControlType', contentType: "application/json", data: { questionType: questionType }, success: function (result) { alert('success'); } }); } 
Sign up to request clarification or add additional context in comments.

Comments

0

if you are looking to pass question type as an argument you should use data:{qType:questionType} this will fill the argument qType of the function GetAttributesForSelectedControlType

1 Comment

it does not matter if it is a simple string or another object. Ideally with what you are doing you should not even hit the controller with what you are doing, if questionType has any value. Any of the solutions posted above is the correct way to do this.
0

Try:

function GetAttributesForSelectedControlType(questionType) { $.get('/Wizards/GetAttributesForSelectedControlType', {questionType: questionType }) .done(function(data) { alert('success'); }); } 

You need to pass in questionType as a data. Alternatively you could just add the follwoing into your existing ajax call.

data: {questionType: questionType } 

This will work with the following action:

public ActionResult GetAttributesForSelectedControlType(string questionType) { // ... } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.