我想控制何时回复错误消息和成功消息,但我总是收到错误消息:
这是我想要做的:
$.ajax({
type: "POST",
data: formData,
url: "/Forms/GetJobData",
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert("success!")
},
error: function (response) {
alert("error") // I'm always get this.
}
});
Run Code Online (Sandbox Code Playgroud)
控制器:
[HttpPost]
public ActionResult GetJobData(Jobs jobData)
{
var mimeType = jobData.File.ContentType;
var isFileSupported = AllowedMimeTypes(mimeType);
if (!isFileSupported){
// Error
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content("The attached file is not supported", MediaTypeNames.Text.Plain);
}
else
{
// Success
Response.StatusCode = (int)HttpStatusCode.OK;
return Content("Message sent!", MediaTypeNames.Text.Plain);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含大量字符串的日志文件.我想从这个文件(查找和替换),除了开头的任何字符串删除一切:phone=与结束Digits=1
例如: phone=97212345678&step=1&digits=1
要找到我正在使用的字符串(phone=.*digits=1),它的工作原理!但我没有找到正则表达式选择除了这个字符串之外的一切,并清除它们.
样本文件.
我试图将文件上传到Linux服务器,但我收到一个错误说:" Unable to connect to the remote server".我不知道我的代码是错还是连接被服务器阻止 - 我可以用FileZilla连接服务器.
我的代码:
const string UserName = "userName";
const string Password = "password";
const string ServerIp = "11.22.333.444/";
public bool UploadFile(HttpPostedFileBase file)
{
string fileName = file.FileName;
var serverUri = new Uri("ftp://" + ServerIp + fileName);
// the serverUri should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
return false;
try
{
// get the object used to communicate with the server.
var request = (FtpWebRequest)WebRequest.Create(serverUri);
request.EnableSsl = true;
request.UsePassive …Run Code Online (Sandbox Code Playgroud) 如何在IHostingEnvironment不在构造函数中启动它的情况下使用该 接口?
我的Startup.cs:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
我的课:
public class FileReader
{
// I don't want to initiate within a constructor
public string ReadFile(string fileName)
{
// this is wrong! how can I use it?
var …Run Code Online (Sandbox Code Playgroud) 我创建了一个信息栏,我想用组件中的信息更新一个区域.我把它作为孩子添加App.vue:
<template>
<div id="app">
<InfoBar /> // my info-bar
<router-view/>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
为了能够<InfoBar />从其他组件更新m ,我决定尝试使用Vuex并使用mutations更改信息:
Vuex商店:
export const store = new Vuex.Store({
state:{
infoBarText: "Text from Vuex store" , // initial text for debugging
},
mutations:{
setInfoBarText(state,text){
state.infoBarText = text;
}
}
Run Code Online (Sandbox Code Playgroud)
infobar.vue
<template>
<div>
{{infoString}} // the result is always "Text from Vuex store"
</div>
</template>
<script>
export default {
name: "infoBar",
data() {
return {
infoString: this.$store.state.infoBarText
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我想使用其他组件的Vuex变异更新文本: …
我试图将两个参数发布到以下函数,但我没有设法达到该函数:
public void SetShopSubCategories([FromBody]string userId, int []subCategories )
{
}
Run Code Online (Sandbox Code Playgroud)
这是我发布的方式:
var subCategories = [ 1, 2, 3, 4, 5];
var userId = "123";
$.ajax({
type: "POST",
url: "/Category/SetShopSubCategories/",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(userId, subCategories),
success: function () {
alert("OK");
},
error: function () {
alert("error");
}
Run Code Online (Sandbox Code Playgroud)
当我只用一个参数发布时,它很顺利,我可以达到这个功能:
public void SetShopSubCategories([FromBody]string userId )
{
}
var userId = "123";
$.ajax({
type: "POST",
url: "/Category/SetShopSubCategories/",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(userId, subCategories),
success: function () {
alert("OK");
},
error: function () { …Run Code Online (Sandbox Code Playgroud) 我有两张桌子:
请求:
RequestID | Msg
----------------
5 | abc
6 | def
7 | ghi
8 | jkl
Run Code Online (Sandbox Code Playgroud)
RequestStatus:
RequestStatusID | RequestID |StatusID
-------------------------------------
1 5 1
2 8 2
Run Code Online (Sandbox Code Playgroud)
RequestStatus我需要表中的所有记录,Request除非StatusID = 2.(requestID=8应该过滤掉)
我LEFT OUTER JOIN用来接收表中的记录,Request但当我添加Where子句时(Where StatusID = 1),它当然不起作用.
我的SQL Server 2014连接字符串是:
Data Source=localhost;Initial Catalog=myDb;Integrated Security=True;
Run Code Online (Sandbox Code Playgroud)
我需要在同一台服务器上安装新的SQL Server 2016实例.因此,我需要修改现有的连接字符串并添加实例名称.
我正在尝试(MSSQLSERVER是实例名称):
"Data Source=localhost\MSSQLSERVER;Initial Catalog=myDb;Integrated Security=True;" providerName="System.Data.SqlClient"
Run Code Online (Sandbox Code Playgroud)
和:
"Server=localhost/MSSQLSERVER;Database=myDb;User Id=user; Password=password;" providerName="System.Data.SqlClient"
Run Code Online (Sandbox Code Playgroud)
更多,但无法使其工作.
我得到的错误是:
找不到网络名称
有没有办法使绑定工作与字符串格式?
<asp:TemplateField HeaderText="Price" >
<EditItemTemplate>
<asp:TextBox ID="txtPrice" runat="server" Text='<%# String.Foramt("{0:#,###}",Bind("Price")) %>' />
</EditItemTemplate>
Run Code Online (Sandbox Code Playgroud) 我试图使用正则表达式匹配引号,但我没有设法逃避它们@string- 我收到一个错误:
output = Regex.Replace(str, @"[\d-']", string.Empty); // valid
output = Regex.Replace(str, @"[\d-'\"]", string.Empty); // not valid!
Run Code Online (Sandbox Code Playgroud)
这个也行不通:
string str = "[\d-'\"]" // bad compile constant value!
Run Code Online (Sandbox Code Playgroud) 我的查询需要帮助:
当我向查询发送值为-1的参数时,我想获取所有记录(此参数不会过滤结果),否则根据值进行过滤.
我正在尝试这样的事情:
WHERE (StatusId = CASE WHEN @StatusId = - 1
THEN
@StatusId IS NULL
ELSE
StatusId = @StatusId END)
Run Code Online (Sandbox Code Playgroud)
谢谢.
我需要选择table1.cloumn它的值何时包含一个值table2.column
我在尝试这个:
select * from Products1 where sku like '%' + (select sku from Products2) + '%'
Run Code Online (Sandbox Code Playgroud) 我正试图从webForms转移到Asp.net-MVC并遇到一些问题.我试图弄清楚为什么这不起作用,我收到此错误:" 对象引用未设置为对象的实例 "
我有课程'Pages':
namespace _2send.Model
{
public class Pages
{
public string PageContent { get; set; }
public string PageName { get; set; }
public int LanguageId { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用此类将值插入'Pages.PageContent'属性:
namespace _2send.Model.Services
{
public class PagesService : IPagesService
{
public void GetFooterlinksPage()
{
DB_utilities db_util = new DB_utilities();
SqlDataReader dr;
Pages pages = new Pages();
using (dr = db_util.procSelect("[Pages_GetPageData]"))
{
if (dr.HasRows)
{
dr.Read();
pages.PageContent = (string)dr["PageContent"];
dr.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
Controller方法如下所示:
private IPagesService _pagesService; …Run Code Online (Sandbox Code Playgroud) sql-server ×4
c# ×3
asp.net-mvc ×2
jquery ×2
.net ×1
ajax ×1
asp.net ×1
asp.net-core ×1
notepad++ ×1
regex ×1
sql ×1
sql-like ×1
vue.js ×1
vuejs2 ×1