当我尝试执行项目时,我收到了这个错误:命名空间不能直接包含成员 [英] When I tried to execute the project I got this error:a namespace cannot directly contain members

查看:201
本文介绍了当我尝试执行项目时,我收到了这个错误:命名空间不能直接包含成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器代码:



This is my Controller Code:

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;
    }





已添加代码块 - OriginalGriff [/ edit]



我尝试了什么:



先生,当我尝试使用WebApi在我的酒店项目中执行bolck room request服务Jvery Ajax在Mvc中我得到了这个错误:命名空间不能直接包含成员

所以请帮帮我。



[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.

推荐答案

无法访问你的完整的代码,我们无能为力 - 像隔离的小片段没有多大帮助,因为错误是非常具体的:

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:

namespace MyNamespace
   {
   public class MyClass
      {
      ...
      }
   public string HotelBlock(string RoomIndexs)
      {
      ...
      }
   }

在C#中,所有字段,属性,方法,代表,活动, - 一切 - 必须是班级的一部分;如果你不是这个错误信息。

In C#, all fields, propertied, methods, delegates, events, - everything - must be part of a class; if it isn't you ghet this error message.


这篇关于当我尝试执行项目时,我收到了这个错误:命名空间不能直接包含成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆