我有一个包含2 @ DropDownListFor的助手的视图:
@using (Html.BeginForm("CreateOneWayTrip", "Trips"))
{
@Html.ValidationSummary(false);
<fieldset>
<legend>Enter Your Trip Details</legend>
<label>Start Point</label>
@Html.DropDownListFor(m => m.StartPointProvince, (SelectList)ViewBag.Provinces, new { @Id = "province_dll", @class = "form-control" })
@Html.DropDownListFor(m => m.StartPointCity, (SelectList)ViewBag.Cities, new { @Id = "city_dll", @class = "form-control" })
<p style="float: none; text-align: center;">
<button type="submit" value="Create" class="btn btn-info btn-circle btn-lg">
<i class="fa fa-check"></i>
</button>
<button type="submit" value="Create" class="btn btn-warning btn-circle btn-lg">
<i class="fa fa-times"></i>
</button>
</p>
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
这是我用来捕获数据的临时模型:
public class CaptureCreateTrip
{
[Required]
[Display(Name = "Trip …
Run Code Online (Sandbox Code Playgroud) 当我创建一个SelecList时,我希望能够手动添加SelecListItem并执行此操作,我使用以下代码:
List<SelectListItem> Provinces = new List<SelectListItem>();
Provinces.Add(new SelectListItem() { Text = "Northern Cape", Value = "NC" });
Provinces.Add(new SelectListItem() { Text = "Free State", Value = "FS" });
Provinces.Add(new SelectListItem() { Text = "Western Cape", Value = "WC" });
SelectList lstProvinces = new SelectList(Provinces);
Run Code Online (Sandbox Code Playgroud)
而不是这个:
var lstProvinces = new SelectList(new[] { "Northern Cape", "Free State", "Western Cape" });
Run Code Online (Sandbox Code Playgroud)
在我创建SelectList之后,我通过ViewBag将它传递给DropDownListFor:
Html.DropDownListFor(m => m.StartPointProvince, (SelectList)ViewBag.Provinces)
Run Code Online (Sandbox Code Playgroud)
但是,当我使用第一种方法创建SelectList时,它不起作用 - 它将3个值添加到下拉列表中,但所有值显示为:
*输出截图
但是,当我使用第二种方法时,它工作正常.我希望使用第一种方法,因为我希望能够指定每个项目的Text AND值.
我正在创建一个简单的库 Swift 包:
import PackageDescription
let package = Package(
name: "dpo-sdk-spm",
platforms: [
.iOS(.v10),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "dpo-sdk-spm",
targets: ["dpo-sdk-spm"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target …
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用 iOS Material 组件,我在这里遇到了选项卡。实现它很容易,在我做了一些小改动以匹配我的设计后,结果就是我想要的:
我使用以下代码实现了这一点:
func setupTabBar() {
let customTabBar = MDCTabBar(frame: view.bounds)
customTabBar.items = [
UITabBarItem(title: "Cards", image: nil, tag: 0),
UITabBarItem(title: "Mobile", image: nil, tag: 0)
]
customTabBar.itemAppearance = .titledImages
customTabBar.alignment = .justified
customTabBar.itemAppearance = .titles
//colors
customTabBar.tintColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
customTabBar.selectedItemTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
customTabBar.unselectedItemTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
customTabBar.barTintColor = UIColor(red:0.00, green:0.33, blue:0.59, alpha:1.0)
tabBarContainerView.addSubview(customTabBar)
customTabBar.sizeToFit()
tabBarContainerView.layer.shadowOffset …
Run Code Online (Sandbox Code Playgroud) 我有一个具有以下结构的对象数组:
{
Name: "Automotive"
RefCategory: 1,
ChildCategories:[{
Name: "Car"
RefCategory: 2,
ChildCategories: []
},{
Name: "Motorcycle"
RefCategory: 3,
ChildCategories: []
}]
}
Run Code Online (Sandbox Code Playgroud)
我编写了一个函数来查找给定 Ref 的类别节点:
navigateToNode(node: any, RefCategoryToFind: number): any {
if (node.RefCategory == RefCategoryToFind)
return node;
node.ChildCategories.forEach(value => {
if (value.RefCategory == RefCategoryToFind)
return value;
else {
if (value.ChildCategories.length !== 0)
return this.navigateToNode(value, RefCategoryToFind);
}
});
}
Run Code Online (Sandbox Code Playgroud)
当我调用这个函数时返回 null
let x = this.navigateToNode(this.activeCategories[0], 2);
Run Code Online (Sandbox Code Playgroud)
我可以看到它击中了return value;
,从而找到了正确的节点,但返回未定义。
我设置了一个简单的打印解决方案,正常打印工作正常(测试了几次),但是当我使用 PrintDialog 指定自定义页面范围时,就好像该范围被忽略了。当我调试时,我检查 printDocument 对象并确认范围值是正确的,但打印机生成的最终产品与我给出的值并不多。
这是我的代码:
printDialog.Document = printdoc;
printDialog.AllowSomePages = true;
if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
printdoc.PrinterSettings.FromPage = printDialog.PrinterSettings.FromPage;
printdoc.PrinterSettings.ToPage = printDialog.PrinterSettings.ToPage;
printdoc.PrinterSettings.PrintRange = printDialog.PrinterSettings.PrintRange;
printPreviewDialog.Document = printdoc;
printPreviewDialog.FindForm().WindowState = FormWindowState.Maximized;
printPreviewDialog.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
*注意 - printdoc 是 System.Drawing.Printing.PrintDocument 的一个实例。我在 PrintDocument 的 PrintPage 事件处理程序中添加了代码来填充我正在打印的页面。
当我在表单中使用 Html.EditorFor 助手时,我希望能够自定义标签的外观,因此我定义了一个 EditorTemplate 来做到这一点。这就是我的表单在我看来的样子:
@model Models.SimpleUserClass
@{
ViewBag.Title = "Create User";
}
<div class="row">
<div class="col-lg-6" id="FromPlaceHoler">
@using (Html.BeginForm("CreateUser", "Users"))
{
<fieldset>
<legend>Create One Way Trip</legend>
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserSurname)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserSurname)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserAge)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserAge)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserGender)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserGender)
</div>
<p>
<input type="submit" value="Create" /> …
Run Code Online (Sandbox Code Playgroud)我想要一个解决方案,一旦向 C# 应用程序发出请求(通过来自网页的 AJAX 帖子),将数据从 C# 应用程序发送到网页,然后使用此处实现的项目,我编写了一个简单的控制台应用程序来监听对于 ajax 帖子。效果很好 - 我点击页面上的一个按钮,将 AJAX 帖子发送到http://localhost:8081/
,这是 HTTP 侦听器正在侦听的端口,然后侦听器回调将一些数据返回到网页,我可以使用这些数据ajax 帖子的成功功能。
我的问题 - 我需要使用http://localhost:8081/index.html
从我的 IIS 服务器请求页面的 URL 打开我的网页,然后我只能启动我的侦听器并按下按钮来触发 AJAX,因为如果我只是保持我的服务运行并导航到该 url我的页面没有显示,而是我的监听器返回的数据而不是 IIS 应该提供的页面。发生这种情况是因为我的侦听器正在侦听的端口与 IIS 在为我的页面提供服务时绑定的端口相同。因此,我决定将 IIS 绑定在端口上8081
,只需将我的 Listener 更改为 Listen on,8083
然后让我的 ajax 也发帖8083
,这样我就可以将 IIS 服务与我为获取数据所做的帖子分开。
这是我的侦听器配置:
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8083/");
listener.Prefixes.Add("http://127.0.0.1:8083/");
listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
Run Code Online (Sandbox Code Playgroud)
这是我的 AJAX 帖子
.ajax({
type: "POST",
url: 'http://localhost:8008/',
data: test_data,
crossDomain: true,
dataType: 'json',
success: function(data) {
//Use data …
Run Code Online (Sandbox Code Playgroud) 作为我们正在构建的应用程序的一部分,其中一个流程步骤是一个AWS Lamda,它可以捕获发布请求并对其进行一些处理,然后再进行移动。它具有一个API网关请求作为触发器,并且此请求的主体将是JSON字符串。我在将JSON字符串解析为GoLang Object时遇到问题。这是我所拥有的:
捕获请求的功能:
func HandleRequest(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
log.Print(fmt.Sprintf("body:[%s] ", event.Body))
parseResponseStringToTypedObject(event.Body)
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Body: "OK",
}, nil
}
Run Code Online (Sandbox Code Playgroud)
然后parseResponseStringToTypedObject
函数:
func parseResponseStringToTypedObject(responseString string) {
b := []byte(responseString)
var resp SimpleType
err := json.Unmarshal(b, &resp)
if err == nil {
log.Print(fmt.Sprintf("Account Name: [%s]", resp.accountName))
} else {
log.Print(fmt.Sprintf("Could not unmarshall JSON string: [%s]", err.Error()))
}
}
Run Code Online (Sandbox Code Playgroud)
这是SimpleType
结构:
type SimpleType struct {
accountName string `json:accountName`
amount int `json:amount`
}
Run Code Online (Sandbox Code Playgroud)
我打开了CloudWatch Logs(我的lamda登录到的地方),看到该 …
c# ×5
ajax ×2
asp.net ×1
asp.net-mvc ×1
go ×1
ios ×1
jquery ×1
json ×1
printdialog ×1
printing ×1
recursion ×1
selectlist ×1
sockets ×1
swift ×1
tree ×1
typescript ×1
web ×1