我有一个WP7游戏,它使用RESTsharp与我的MVC4 RESTful服务器进行通信,但是我经常遇到使请求有效的问题,因此我想调试它失败的地方.
这是一个示例,其中我的构造函数GameController
被命中,但Post
方法没有被击中,我不明白为什么.
客户代码:
public void JoinRandomGame()
{
client = new RestClient
{
CookieContainer = new CookieContainer(),
BaseUrl = "http://localhost:21688/api/",
};
client.Authenticator = GetAuth();
RestRequest request = new RestRequest(Method.POST)
{
RequestFormat = DataFormat.Json,
Resource = "game/"
};
client.PostAsync(request, (response, ds) =>
{});
}
Run Code Online (Sandbox Code Playgroud)
服务器代码:
public void Post(int id)
{
if (ControllerContext.Request.Headers.Authorization == null)
{
//No auth
}
if (!loginManager.VerifyLogin(ControllerContext.Request.Headers.Authorization.Parameter))
{
//Failed login
}
string username;
string password;
LoginManager.DecodeBase64(ControllerContext.Request.Headers.Authorization.Parameter, out username, out password);
gameManager.JoinRandomGame(username);
}
Run Code Online (Sandbox Code Playgroud)
我的路线是这样的
routes.MapHttpRoute( …
Run Code Online (Sandbox Code Playgroud) 我试图在我的MVC 6上运行一些d3js并且正在查看这个示例https://github.com/DustinEwers/D3-DotNetMVC-Demos/blob/master/D3Demos/Views/TagDemos/BasicBarChart.cshtml它使用
@Scripts.Render("~/bundles/d3")
@section Scripts{
Run Code Online (Sandbox Code Playgroud)
但如果我这样做,我得到
当前上下文中不存在"脚本"这个名称
那么在MVC 6中有一种新的方法吗?
我尝试下载Blend 3但是即使安装了它,我也无法在.NET下找到该文件.如果我尝试从C:\ Program Files(x86)\ Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries\WPF添加引用并使用此代码http://pastebin.com/VdeRyPdv我收到文件错误没找到.它还在我的调试文件夹中添加了许多文件夹,如en,de es fr等.
我的API atm有2条API路由,但我想添加更多,而我这样做的方式似乎互相覆盖,所以在我粘贴的代码中,只有CreateUser
路由有效.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "CreateUser",
routeTemplate: "api/{controller}/{cUser}",
defaults: new
{
controller = "User",
action = "CreateUser",
cUser = RouteParameter.Optional
});
routes.MapHttpRoute(
name: "AllGames",
routeTemplate: "api/{controller}/{playerId}",
defaults: new
{
controller = "Game",
action = "GetAllGames",
playerId = RouteParameter.Optional
});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
}
Run Code Online (Sandbox Code Playgroud) asp.net-mvc asp.net-mvc-routing asp.net-mvc-4 asp.net-web-api
我在ViewModel中有一个List,我解析为View
List<BoolSetting>
Run Code Online (Sandbox Code Playgroud)
BoolSetting:
public class BoolSetting
{
public BoolSetting(string displayName, bool value)
{
DisplayName = displayName;
Value = value;
}
public string DisplayName { get; set; }
public bool Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后,我想打印列表中所有项目的复选框,因此列表位于视图使用的ViewModel中
@foreach(var boolSettingList in Model.BoolSettingList)
{
<div>
@Html.CheckBox(boolSettingList.DisplayName, boolSettingList.Value)
@boolSettingList.DisplayName
</div>
}
Run Code Online (Sandbox Code Playgroud)
问题是当我发布这个时,我的模型没有在我的ViewModel中的List中保存更新的设置(bool值),因此该对象为空.
我可以
foreach (var VARIABLE in userSettingConfigViewModel.BoolSettingList)
{
VARIABLE.Value = (bool)Request.Form[VARIABLE.DisplayName];
}
Run Code Online (Sandbox Code Playgroud)
但是这个视图模型将有许多列表,其中一些将具有相同的名称!这样会引起冲突
那么有没有办法预先打印我所有的bool然后让MVC弄清楚将数据放回到List对象之后?我不能让CheckBoxFor工作,因为它想要一个表达式,我无法找到一种方法来通过我的列表迭代
我可以通过为BoolSetting制作模板并使用List来修复模板吗?
我在我的UI.Droid/Resources/Values中有MvxBindingAttributes.xml,但每次我尝试在我的布局中使用绑定时,我得到
未声明警告属性.
在'DroidUI'包中找不到属性'MvxBind'的资源标识符
所以由于某种原因它找不到那些属性.我试图关闭/重新打开/清理/重建没有运气,尝试删除布局然后构建(希望它会在构建时添加它们)然后尝试再次添加它们,但似乎没有任何工作
我有一个按钮
<Button
android:id="@+id/ButtonConnect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Disconnect"
local:MvxBind="{'Click':{'Path':'DisconnectCommand'}}" />
Run Code Online (Sandbox Code Playgroud)
我有一个命令
public IMvxCommand DisconnectCommand
{
get
{
return new MvxRelayCommand(this.GetService<IConnectionService>().Disconnect);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我想使用启用/禁用DisconnectCommand
DisconnectCommand.CanExecute(this.GetService<IConnectionService>().UsbConnected);
Run Code Online (Sandbox Code Playgroud)
但这显然是错误的(它不起作用),我把检查作为一个参数,但通常我会这样做
DisconnectCommand.CanExecute = someBool;
Run Code Online (Sandbox Code Playgroud)
但是没有设置属性,所以如何去做呢?
我有一个类型为Project的可观察集合,我希望在ListView中显示但是没有添加到我的ListView中,我真的不明白
我的MainWindow.xaml
<ListView Name="ListViewProjects" Grid.Column="0" Grid.RowSpan="3" SelectionChanged="ListViewProjectsSelectionChanged" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" MinWidth="100">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding Path=ProjectID}"/>
<TextBlock Text="{Binding Path=ProjectName}"/>
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
我的MainWindow.cs
public partial class MainWindow : Window
{
ObservableCollection<Project> Projects = new ObservableCollection<Project>();
ObservableCollection<Employee> Employees = new ObservableCollection<Employee>();
public MainWindow()
{
InitializeComponent();
DataContext = Projects;
Project pro1 = new Project(1, "Swordfish");
Projects.Add(pro1);
Employee empMads = new Employee("Mads", 1);
Employee empBrian = new Employee("Brian", 2);
Employees.Add(empMads);
Employees.Add(empBrian);
}
private void ListViewProjectsSelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
Run Code Online (Sandbox Code Playgroud)
和我的Project.cs这是类文件 …
我正在尝试创建一个类,当它启动时,它会启动一个秒表,并且所有时间都将经过的时间写入本地变量 Elapsed,我有一个数据绑定到的 Listview。但是当我使用这段代码时,Listview 只显示 00:00:00.00000001 并且永远不会改变。类的代码是:
命名空间 project23 { 公共类 ActiveEmployee { 公共 int EmpID { 获取;放; } 公共字符串 EmpName { 获取;放; } 私人日期时间日期; 私人 BackgroundWorker 工作者; 公共秒表 sw; 公共 ActiveEmployee(int empID,字符串 empName) { 日期 = DateTime.Now; worker = new BackgroundWorker(); worker.DoWork += 后台工作; worker.WorkerReportsProgress = true; worker.RunWorkerAsync(); } 私人时间跨度已过; 公共时间跨度已过 { 得到 { 返回已过;} 放 { 已用时间 = 值; NotifyPropertyChanged("Elapsed"); } } 私有无效BackgroundWork(对象发送者,DoWorkEventArgs args) { sw = 新秒表(); sw.开始(); 如果是真的) { Elapsed = sw.Elapsed; } } 公共事件 PropertyChangedEventHandler PropertyChanged; …
从我所看到的,我必须为我想通过WCF传输的每种数据创建一个"特殊"数据类型,所以如果我有一个像这样的共享类
public class District
{
public long Id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想使用WCF发送一个District对象,我必须创建一个datacontract,因此我必须创建一个新的WCF类
[DataContract]
public class WCFDistrict
{
[DataMember]
public long Id { get; set; }
[DataMember]
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后当我在我的实现中的WCF服务中使用它时,我必须将数据从一个对象解析到另一个对象
public WCFDistrict GetDistrict(long id)
{
var district = _districtRepository.GetDistrict(id);
return new WCFDistrict {Id = district.Id, Name = district.Name};
}
Run Code Online (Sandbox Code Playgroud)
有没有办法只重用共享类作为DataContract,而没有这些属性?或者我应该在他们可以共享的类上创建一个接口,以便我可以在它们之间进行转换?还是第三种?
c# ×6
.net ×5
asp.net-mvc ×3
wpf ×3
binding ×2
mvvmcross ×2
d3.js ×1
data-binding ×1
rest ×1
wcf ×1