我试图在WebAPI控制器上发布多个参数.一个参数来自URL,另一个参数来自正文.这是网址:
/offers/40D5E19D-0CD5-4FBD-92F8-43FDBB475333/prices/
这是我的控制器代码:
public HttpResponseMessage Put(Guid offerId, OfferPriceParameters offerPriceParameters)
{
//What!?
var ser = new DataContractJsonSerializer(typeof(OfferPriceParameters));
HttpContext.Current.Request.InputStream.Position = 0;
var what = ser.ReadObject(HttpContext.Current.Request.InputStream);
return new HttpResponseMessage(HttpStatusCode.Created);
}
Run Code Online (Sandbox Code Playgroud)
正文的内容是JSON:
{
"Associations":
{
"list": [
{
"FromEntityId":"276774bb-9bd9-4bbd-a7e7-6ed3d69f196f",
"ToEntityId":"ed0d2616-f707-446b-9e40-b77b94fb7d2b",
"Types":
{
"list":[
{
"BillingCommitment":5,
"BillingCycle":5,
"Prices":
{
"list":[
{
"CurrencyId":"274d24c9-7d0b-40ea-a936-e800d74ead53",
"RecurringFee":4,
"SetupFee":5
}]
}
}]
}
}]
}
}
Run Code Online (Sandbox Code Playgroud)
知道为什么默认绑定无法绑定到offerPriceParameters
我的控制器的参数?它始终设置为null.但是我能够使用the从身体恢复数据DataContractJsonSerializer
.
我也尝试使用FromBody
参数的属性,但它也不起作用.
我有以下测试代码:
parentViewModel = MockRepository.GenerateMock<IParentViewModel>();
parentViewModel.Expect(x => x.GetPropertyValue<IEnumerable<Milestone>>("JobMilestones")).Return(new Milestone[0]);
viewModel = new JobPenaltiesViewModel(j, new Penalty[0], _opContext, parentViewModel);
Assert.That(viewModel.Milestones.Count(), Is.EqualTo(0));
parentViewModel.VerifyAllExpectations();
List<string> propsChanged = new List<string>();
viewModel.PropertyChanged += (s, e) => propsChanged.Add(e.PropertyName);
parentViewModel.Raise(x => x.PropertyChanged += null, parentViewModel, new PropertyChangedEventArgs("JobMilestones"));
AssertPropertiesChangedAsExepected(propsChanged, 1, "Milestones");
Milestone m1 = GenerateMilestone(j);
List<Milestone> milestones1 = new List<Milestone> { m1 };
parentViewModel.Expect(x => x.GetPropertyValue<IEnumerable<Milestone>>("JobMilestones")).Return(milestones1).Repeat.Any();
IEnumerable<Milestone> milestones = viewModel.Milestones;
Assert.That(milestones.Count(), Is.EqualTo(1));
parentViewModel.VerifyAllExpectations();
Run Code Online (Sandbox Code Playgroud)
所有测试和断言都会成功,直到:
Assert.That(milestones.Count(), Is.EqualTo(1));
Run Code Online (Sandbox Code Playgroud)
这就是我得到例外的地方:
Previous method 'IEnumerator.MoveNext();' requires a return value or an exception to throw.
Run Code Online (Sandbox Code Playgroud)
我已经尝试了我能想到的一切,我的测试似乎表明parentViewModel …
我是Java的新手,并尝试使用EditText创建一个活动.在创建时,它使用当前日期加载,当用户选择EditText时,它会显示DatePicker.一旦用户选择了日期,我需要将结果放入EditText.但是,我目前收到以下错误:
无法从类型Activity对静态方法findViewById(int)进行静态引用
我知道我不能对非静态方法进行静态引用.我试图删除所有静态引用,但这给了我其他错误.我的代码如下.
你能帮我一些关于如何使这项工作的示例代码吗?错误是在我尝试将结果放入EditText的位置.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get Current Date and assign to EditText Begin
Calendar c = Calendar.getInstance();
System.out.println("Current time => " + c.getTime());
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
String formattedDate = df.format(c.getTime());
EditText ShowDate = (EditText) findViewById(R.id.editTextToShowDate);
ShowDate.setText(formattedDate);
//Get Current Date and assign to EditText End
}
//Date Picker Start
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public …
Run Code Online (Sandbox Code Playgroud) 假设我希望能够比较2个整数列表并将一个特定值视为外卡.
例如,如果-1是外卡,那么
{1,2,3,4} == {1,2,-1,4} //returns true
我正在编写一个类来包装所有这些逻辑,因此它实现IEquatable
并具有相关的逻辑public override bool Equals()
但是,GetHashCode
如果你压倒一切,我一直认为你或多或少必须实施.Equals()
.虽然它没有被编译器强制执行,但我一直认为如果你不这样做那么你做错了.
除非我不知道如何在.GetHashCode()
不破坏合同的情况下实现(Equal的对象具有不同的哈希值),或者只是执行实现return 1
.
思考?
我想加载BufferedImage
我的应用程序.为此,我正在使用,ImageIO
但我得到java.lang.NoClassDefFoundError
:
BufferedImage tgtImg = loadImage("ImageD2.jpg");
public static BufferedImage loadImage(String ref) {
BufferedImage bimg = null;
try {
bimg = ImageIO.read(new File(ref));
} catch (Exception e) {
e.printStackTrace();
}
return bimg;
}
Run Code Online (Sandbox Code Playgroud)
但我得到例外:
03-15 18:05:22.051: ERROR/AndroidRuntime(437): java.lang.NoClassDefFoundError: javax.imageio.ImageIO
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它应该接受来自Salesforce的不安全字符.它们是%0A和%0D(到目前为止......)并且它们不起作用.
我已经设置allowDoubleEscaping
到true
,requestValidationMode
对2.0
,requestPathInvalidCharacters
对BLANK
,relaxedUrlToFileSystemMapping
对true
,并maxRequestLength
到1024
.
它没用.然后我尝试将400的自定义错误设置为重定向到同一页面,而不传递Salesforce发送的数据.也没工作.
然后我尝试通过IIS 7错误页面部分执行相同操作,但它仍然无法正常工作.
我怎么能够:
所有这些都在ASP.NET MVC 3应用程序中,但我怀疑这很重要,因为它可能会在它调用ASP.NET运行时之前阻止它.
我很感激一些帮助.提前致谢!
很长一段时间WinForm程序员在这里,但新的Web编程场景.我有Visual Studio 2010,我创建了一个新的WebSite项目.我似乎无法得到ajax来调用我创建的web方法.当我点击页面上的按钮时,根本没有任何事情发生.
在创建WebSite项目时,看起来jquery 1.4.1会自动添加到Scripts文件夹中.
在Default.aspx中,我添加了2个脚本标记:
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="Scripts/Process.js">
Run Code Online (Sandbox Code Playgroud)
我在页面上放了一个按钮,在Process.js中定义了onclick函数:
<input id="btnTest" type="button" value="Test" onclick="btnTest_onclick()" />
Run Code Online (Sandbox Code Playgroud)
在Process.js中,我有以下代码:
function btnTest_onclick() {
var strData = JSON.stringify({
userid: 5
});
alert(strData);
$.ajax({
url: 'Default.aspx/GetData',
type: "POST",
data: strData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
failure: Failure,
async: true
});
}
function Success(data) {
alert("success");
}
function Failure(data) {
alert("failure");
}
Run Code Online (Sandbox Code Playgroud)
在Default.aspx.cs中:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
} …
Run Code Online (Sandbox Code Playgroud) 完成从 Angular 5.x 到 8.0.1 的更新后,我的应用程序可以编译,但在运行时出现以下错误(使用ng serve
):
错误:未设置基本 href。请为 APP_BASE_HREF 令牌提供值或向文档添加基本元素。
我看过其他帖子,例如:Angular 2 router no base href set,但是,我的应用程序中已经包含 HTML 基本元素。我index.html
的如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<app-root></app-root>
</html>
Run Code Online (Sandbox Code Playgroud)
我可以通过添加来解决问题:
{
provide: APP_BASE_HREF,
useValue: '/'
}
Run Code Online (Sandbox Code Playgroud)
到我的app.modules.ts
,但我更感兴趣的是了解为什么现在需要这样做,当使用ng new
该提供程序创建的裸机应用程序在没有此提供程序的情况下工作时。
我正在尝试使用MVVM模式在UWP中创建一个应用程序.作为Listbox中项目的DataTemplate的usercontrol可能有自己的VM.
这是MainPage.xaml的一部分
<ListBox Name="ListBox1" ItemsSource="{Binding Components}">
<ListBox.ItemTemplate >
<DataTemplate x:DataType="vm:ComponentUserControlViewModel" >
<local:ComponentUserControl />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
MainPageVM包含:
public ObservableCollection<Component> Components
Run Code Online (Sandbox Code Playgroud)
现在它是我的UserControl
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Text="{Binding Id}" Grid.Row="0"></TextBox>
<TextBox Text="{Binding Name}" Grid.Row="1"></TextBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
VM:
public class ComponentUserControlViewModel : ViewModelBase
{
private string _componentId;
private string _componentName;
public ComponentUserControlViewModel()
{
}
public string Id
{
get { return _componentId; }
set
{
SetProperty(ref _componentId, value);
}
}
public string Name
{
get { return _componentName; …
Run Code Online (Sandbox Code Playgroud) 我想为我的 SignInManager 创建一个自定义类,所以我创建了一个继承自的类,SignInManager<>
如下所示:
public class ApplicationSignInManager : SignInManager<ApplicationUser>
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly ApplicationDbContext _dbContext;
private readonly IHttpContextAccessor _contextAccessor;
public ApplicationSignInManager(
UserManager<ApplicationUser> userManager,
IHttpContextAccessor contextAccessor,
IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory,
IOptions<IdentityOptions> optionsAccessor,
ILogger<SignInManager<ApplicationUser>> logger,
ApplicationDbContext dbContext,
IAuthenticationSchemeProvider schemeProvider
)
: base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemeProvider)
{
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
_contextAccessor = contextAccessor ?? throw new ArgumentNullException(nameof(contextAccessor));
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将它添加到服务配置中Startup.cs
:
services.AddDefaultIdentity<ApplicationUser>(configure =>
{
configure.User.AllowedUserNameCharacters += " …
Run Code Online (Sandbox Code Playgroud) .net ×2
android ×2
asp.net ×2
c# ×2
ajax ×1
angular ×1
asp.net-core ×1
asp.net-mvc ×1
c#-4.0 ×1
hashcode ×1
iequatable ×1
iis ×1
iis-7 ×1
jquery ×1
rhino-mocks ×1
unit-testing ×1
wildcard ×1