2

I am using asp.net web api.I am using MVC with that. I am trying to call below ajax call but it alway give me 404 error.

It I try without three parameters "Hash", "AccessKey","Path" - then it allows me to call method of http://www.xxx.xys/rest/createnew and gives response good as I wish.

but when I add these three("Hash", "AccessKey","Path" ) parameters it always gives me error not found(404) error.

here no error due to cross domain as becuase it is running good wihtout three parameters. I want to pass three parameters as argument not as properties of object CreateParameter.not in header requset. only I want to pass them in parameters.

 function CreateTicket() {

        $.ajax({
            url: 'http://www.xxx.xys/rest/createnew',

            type: 'POST',
            dataType: 'json',
            data: {
                MerchantID: $("#txtMerchantID").val(), TicketCategoryID: $("#txtTicketCategoryID").val(), GroupID: $("#txtGroupID").val(), TicketSubCategoryID: $("#txtSubCategoryID").val(), TicketPriorityID: $("#txtTicketPriorityID").val(), Summary: '' + $("#txtSubject").val() + '',
Hash: "EI2nkSoqRN5cBO/ctXF90tl+c0UTW/euI8NZwsG8ZBE=", AccessKey: "d357cf6e-bb14-452e-8044-68c699503c2b", Path: "api/TicketAPIs/GetTicketsByFilter"
            },
            crossDomain: true,
            ContentType: "application/json; charset=utf-8",
            success: function (data) {
                if (data.IsSuccess) {

                    alert('created');
                }
                else {
                    alert('error');
                }

            },
            error: function (data) {
                    alert('error');
            }
        });
    }

and

 [HttpPost]
    public CreateTicketResult createnew([FromBody]CreateParameter ObjParameter,string Hash, string AccessKey, string Path)
    {
        //code here
}
and I have also tried with below but not working.

[HttpPost]
    public CreateTicketResult createnew(CreateParameter ObjParameter,string Hash, string AccessKey, string Path)
    {
        //code here
}


 public class CreateParameter
    {

        public int MerchantID { get; set; }
        public short TicketCategoryID { get; set; }
        public short GroupID { get; set; }
        public short TicketSubCategoryID { get; set; }
        public short TicketPriorityID { get; set; }
        public string Summary { get; set; }
    }

so I want to pass MerchantID,TicketCategoryID,GroupID,TicketSubCategoryID,TicketPriorityID, Summary as property of object of CreateParameter and these three("Hash", "AccessKey","Path" ) as seperate parameters as shown in signature of function createnew. but could not able to do so.

1 Answer 1

1

EDITED ANSWER Try this in the controller:

public CreateTicketResult createnew(string MerchantID, string TicketCategoryID, string GroupID, string TicketSubCategoryID, string TicketPriorityID, string Summary,string Hash, string AccessKey, string Path)
{
   CreateParameter ObjParameter = new CreateParameter();
        ObjParameter.MerchantID = MerchantID;
        ObjParameter.TicketCategoryID = TicketCategoryID;
        ObjParameter.GroupID = GroupID;
        ObjParameter.TicketSubCategoryID = TicketSubCategoryID;
        ObjParameter.TicketPriorityID = TicketPriorityID;
        ObjParameter.Summary = Summary;


//code..........
//code.......
}

Else, use make a json object and pass it in the request so you can decode in in the controller, but the above method is much easier. It's all up to your preference.

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

5 Comments

i tried the endodeURIcomponent but it is now working,
@Nishal -i tried the endodeURIcomponent but it is now working, also I have tried like Hash: "s", AccessKey: "ss", Path: "sd" but not working
Great! Can you kindly answer your own question with the working code?
sorry!.I have not found any solution yet, can you please do the needful more in depth? as soon as I got solution I will definetely post answer on my question.
I have a suggestion here @skiskd, you are passing 9 (all of them string) parameters to the controller, whereas the controller only accepts 4. This HAS to cause some error. Why don't you make the controller accept all 9 string parameters as it is, and then create the CreateParameter object somewhere inside the method? Or else use json to pass objects. I will update my answer with my first suggestion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.