Click here to Skip to main content
15,885,921 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my Controller Code:

C#
public string HotelBlock(string RoomIndexs)
    {
        HotelRoomsDetails hd = JsonConvert.DeserializeObject<hotelroomsdetails>(RoomIndexs);
        //HotelResult hotelResult = JsonConvert.DeserializeObject<hotelresult>();
        string sre = "sdddddddd";
        BlockRoomReqest block = new BlockRoomReqest();
        block.EndUserIp = "";
        block.GuestNationality = "";
        block.HotelCode = "";
        block.HotelName = "";
        block.NoOfRooms = 1;
        block.ResultIndex = 1;
        block.TokenId = "";
        block.TraceId = "";
        block.HtlRoom = new List<hotelroomsdetails>()
            {
                new HotelRoomsDetails{RoomTypeCode=hd.RoomTypeCode,
                                     RoomIndex=hd.RoomIndex,
                                     RoomTypeName=hd.RoomTypeName,
                                     RatePlanCode =hd.RatePlanCode,
                                     RatePlanName =hd.RatePlanName,
                                     SmokingPreference =null,
                                     SequenceNo =null,
                                     //Price=new Price
                                     //{
                                     //    CurrencyCode="",PublishedPrice=,PublishedPriceRoundedOff=54387
                                     //}
                }

            };
        block.IsVoucherBooking = true;
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri("http://api.tektravels.com/BookingEngineService_Hotel/hotelservice.svc/");
        MediaTypeWithQualityHeaderValue type = new MediaTypeWithQualityHeaderValue("application/json");
        client.DefaultRequestHeaders.Accept.Add(type);
        var contentdata = new StringContent(JsonConvert.SerializeObject(block), Encoding.UTF8, "application/json");
        HttpResponseMessage response = client.PostAsync("rest/BlockRoom", contentdata).Result;
        string stringdata = response.Content.ReadAsStringAsync().Result;
        JObject jObject = (JObject)JsonConvert.DeserializeObject(stringdata);
        return sre;
    }


[edit]Code block added - OriginalGriff[/edit]

What I have tried:

sir, When i tried to execute bolck room request in my hotel project using WebApi service Jquery Ajax in Mvc i got this error:a namespace cannot directly contain members
so please help me.
Posted
Updated 12-Jun-18 22:33pm
v2
Comments
Richard MacCutchan 13-Jun-18 4:25am    
Please edit your question and add the proper <pre> tags around your code so it is readable. And please indicate where this message occurs.
Member 13823448 13-Jun-18 6:19am    
hi sir please send me the code fo rto display the hotels data per one night using WebApi Jquery Ajaz in Mvc

1 solution

Without access to your full code, we can't help much - a small fragment like that in isolation doesn't help much because the error is pretty specific:
A namespace cannot directly contain members

But ... the most likely reason is you have put the method in the wrong place, and it's after the closing curly bracket for the class:
C#
namespace MyNamespace
   {
   public class MyClass
      {
      ...
      }
   public string HotelBlock(string RoomIndexs)
      {
      ...
      }
   }
In C#, all fields, propertied, methods, delegates, events, - everything - must be part of a class; if it isn't you ghet this error message.
 
Share this answer
 
Comments
Member 13823448 15-Jun-18 3:42am    
Thank u sir
OriginalGriff 15-Jun-18 4:11am    
You're welcome!

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