我正在将多部分表单数据发送到我的WebApi控制器.我感兴趣的内容包括图像和另一个非图像值.我可以读取图像没问题,但无法弄清楚如何读取用户名部分(以andy作为值).它不在提供程序的FormData属性中.我怎么才能得到它?
多部分表单数据
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Filename"
image.jpg
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="username"
andy
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Filedata"; filename="image.jpg"
Content-Type: application/octet-stream
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Upload"
Submit Query
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0--
Run Code Online (Sandbox Code Playgroud)
控制器代码
string root = System.Web.HttpContext.Current.Server.MapPath("~/App_Data");
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(root);
var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>(o =>
{
...
}
Run Code Online (Sandbox Code Playgroud) 使用此代码:
OracleDataTable dt = PlatypusSchedData.GetAvailablePlatypi();
OracleDataTable outputDt = new OracleDataTable();
int iRows = 12;
while (iRows > 0)
{
outputDt.Rows.Add(new DataRow()); // line 1
//var dr = new DataRow(); // line 2a
//outputDt.Rows.Add(dr); // line 2b
iRows -= 1;
}
for (int i = 0; i < dt.Rows.Count; i += 1) {
DataRow dr = dt.Rows[i];
int outputColumn = 0;
if (i % 12 == 0 && i > 0) {
outputColumn += 1; //2?
}
outputDt.Rows[i % 12][outputColumn] = …Run Code Online (Sandbox Code Playgroud) 我只需要允许将一个字符输入到可编辑的 datagridview 单元格中(每隔一列,奇数列都是可编辑的);如果用户在其中一个单元格中添加第二个字符,则光标应向下移动到下一个单元格并将第二个值放在那里(再次按下该键再次向下移动,依此类推)。如果在网格的底部(第 12 行),它应该移动到第 0 行并向右移动两列。
我尝试这样做:
private void dataGridViewPlatypus_KeyDown(object sender, KeyEventArgs e) {
var currentCell = dataGridViewPlatypus.CurrentCell;
int currentCol = currentCell.ColumnIndex;
int currentRow = currentCell.RowIndex;
if (currentCell.Value.ToString().Length > 0) {
if (currentRow < 11) {
dataGridViewPlatypus.CurrentCell.RowIndex = currentRow+1;
} else if (currentRow == 11) {
currentCell.RowIndex = 0;
currentCell.ColumnIndex = currentCell.ColumnIndex + 2;
dataGridViewPlatypus.CurrentCell = currentCell;
}
}
}
Run Code Online (Sandbox Code Playgroud)
...但我收到 RowIndex 和 ColumnIndex 无法分配的错误消息,因为它们是只读的。
那么我怎样才能做到这一点呢?
警告:我知道如果当前位于最后一个可编辑列的底部,我还必须添加逻辑以移动到第 1 列。
从 tergiver 的回答来看,这是我到目前为止所得到的,但我不知道如何前进到下一个单元格。
protected override bool ProcessCmdKey(ref Message msg, …Run Code Online (Sandbox Code Playgroud) 使用此代码(带或不带".ToList()"):
public async Task<List<String>> SelectDistinctGroupNames()
{
var db = new SQLiteAsyncConnection(SQLitePath);
var groupNames = await db.QueryAsync<List<string>>("SELECT DISTINCT GroupName FROM SOs_Locations");
return groupNames.ToList();
}
Run Code Online (Sandbox Code Playgroud)
...我得到," 不能隐式地将类型'System.Collections.Generic.List>'转换为'System.Collections.Generic.List' "
这有效:
public async Task<HashSet<String>> SelectDistinctGroupNames()
{
var db = new SQLiteAsyncConnection(SQLitePath);
var allLocations = await db.QueryAsync<SOs_Locations>("SELECT * FROM SOs_Locations ORDER BY GroupName");
HashSet<string> hashsetGroupNames = null;
foreach (var item in allLocations)
{
hashsetGroupNames.Add(item.GroupName);
}
return hashsetGroupNames;
}
Run Code Online (Sandbox Code Playgroud)
...但似乎很浪费(抓住所有记录,当我想要的只是GroupName列中的不同值).
在我看来,当用"DISTINCT GroupName"替换sql查询中的"*"时,需要的是List或者甚至是HashSet
那么当返回几个记录中的单个列时,究竟返回了什么?IOW,在QueryAsync <>()调用的尖括号内应该是什么?
我认为这会奏效:
public async Task<List<String>> SelectDistinctGroupNames()
{
var db = new SQLiteAsyncConnection(SQLitePath);
List<string> …Run Code Online (Sandbox Code Playgroud) 有了这个:
if (args.Parameter == "ContactIntermediaryPage")
Run Code Online (Sandbox Code Playgroud)
...在NavigatedTo()事件处理程序中,Resharper告诉我:"可能的非预期参考比较;要获得值比较,请将左侧投射到'string'类型"
所以我应该将其更改为以下之一,如果是,那么哪一个:
if ((string)args.Parameter == "ContactIntermediaryPage")
if (args.Parameter.ToString() == "ContactIntermediaryPage")
if (args.Parameter.Equals("ContactIntermediaryPage"))
Run Code Online (Sandbox Code Playgroud) 我想有条件地改变用户在我要创建的照片库网站上看到的内容,具体取决于用于查看网站的设备是纵向/垂直还是横向/水平模式/方向.这可能吗?
javascript jquery screen-orientation jquery-mobile landscape-portrait
在页面处于"休眠"状态期间,我可以通过在Chrome开发工具的控制台选项卡中输入其ID来检查任何标记的值,例如,对于名称为"BeginDate"的标记:
0)在控制台选项卡中输入"BeginDate"1)将键移动
......我看到整个shebang:
<input alt="date-us" data-val="true" data-val-regex="End Date must be in the format &quot;m/d/yyyy&quot;" data-val-regex-pattern="[0-9]*[0-9]/[0-9]*[0-9]/[0-9]{4}" data-val-required="End Date must be in the format &quot;m/d/yyyy&quot;" id="EndDate" name="EndDate" style="width: 164px;" type="text" value="5/14/2013" class="hasDatepicker">
Run Code Online (Sandbox Code Playgroud)
因此,它显示的价值是我感兴趣的部分,是今天的日期.
但是,我想要检查的是在按下表单的"提交"按钮时传递/发布的内容; 我相信在asp.net中,这将是Request对象的内容,但是如何使用Chrome Dev Tools查看这些val?
我右键单击在控制台中选择了"日志的XMLHttpRequest"和"保存日志在导航"可是......他们是登录?如果是这样,他们在哪里?我在Console选项卡中看不到任何内容......
感谢David Ziemann,这就是我所看到的:

使用此输入复选框:
<input type="checkbox">Click moi!
Run Code Online (Sandbox Code Playgroud)
...还有这个CSS:
input[type=checkbox] {
color:green;
font-family: Consolas, Baskerville, 'Segoe UI', sans-serif;
}
input[type=checkbox]:hover {
box-shadow:0px 0px 10px #1300ff;
}
Run Code Online (Sandbox Code Playgroud)
...悬停位工作正常(复选框本身会更改),但文本的颜色/字体(“单击 moi!”)不受设置颜色和字体系列的影响。
jsfiddle:http : //jsfiddle.net/QRBEx/
如何通过 CSS 影响文本属性?
在对如何执行此操作感到困惑之后(如此处和此处所示),我现在使用以下代码成功连接到我的服务器应用程序和适当的 RESTful 方法:
public void onFetchBtnClicked(View v){
if(v.getId() == R.id.FetchBtn){
Toast.makeText(getApplicationContext(), "You mashed the button, dude.", Toast.LENGTH_SHORT).show();
new CallAPI().execute("http://10.0.2.2:28642/api/Departments/GetCount?serialNum=4242");
}
}
public static class CallAPI extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
String urlString=params[0]; // URL to call
String resultToDisplay = "";
InputStream in = null;
// HTTP Get
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream());
} catch (Exception e ) {
System.out.println(e.getMessage()); …Run Code Online (Sandbox Code Playgroud) 我保留的一些遗留代码卡在无限循环中(因此我自己似乎在一个); 但是,我无法弄清楚为什么/如何.
这是应用程序的入口点,它实例化主窗体(frmCentral):
代码展览A.
public static int Main(string [] args)
{
try
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler);
string name = Assembly.GetExecutingAssembly().GetName().Name;
MessageBox.Show(string.Format("Executing assembly is {0}", name)); // TODO: Remove after testing <= this one is seen
IntPtr mutexHandle = CreateMutex(IntPtr.Zero, true, name);
long error = GetLastError();
MessageBox.Show(string.Format("Last error int was {0}", error.ToString())); // TODO: Remove after testing <= this one is also seen
if (error == ERROR_ALREADY_EXISTS)
{
ReleaseMutex(mutexHandle);
IntPtr hWnd = FindWindow("#NETCF_AGL_BASE_", null);
if ((int) …Run Code Online (Sandbox Code Playgroud) c# messagebox infinite-loop mutual-recursion visual-studio-debugging
c# ×6
android ×1
async-await ×1
css ×1
datagridview ×1
dotconnect ×1
dynamic ×1
form-submit ×1
forms ×1
html ×1
http-get ×1
java ×1
javascript ×1
jquery ×1
keydown ×1
linq-to-sql ×1
messagebox ×1
oracle ×1
refactoring ×1
reference ×1
resharper ×1
return-type ×1
sqlite ×1
windows ×1
winforms ×1