标签助手不使用剃刀

时间:2017-05-17 13:05:06

标签: c# razor asp.net-core asp.net-core-tag-helpers

我正在创建一个部分视图来渲染列表的输入。问题是我需要使用razor代码提供asp-for属性,如下所示:

@Html.Partial("Partial",
  Model.MyList,
  new ViewDataDictionary(this.ViewData){
    { "AspFor", "MyList" }
  });

我称之为部分使用:

<label for="ViewData_AspFor_">ViewData[AspFor]</label>
<input value="item 1" type="text" id="ViewData_AspFor_" name="ViewData[AspFor]">

呈现:

  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            // Modify the notification content here...
            if let imagePath = request.content.userInfo["image"] as? String {
                guard let url = URL(string: imagePath) else {
                    contentHandler(bestAttemptContent)
                    return
                }
                guard let imageData = NSData(contentsOf: url) else {
                    contentHandler(bestAttemptContent)
                    return
                }
                guard let attachment = UNNotificationAttachment.create(imageFileIdentifier: "image.jpg", data: imageData, options: nil) else {
                    print("error in UNNotificationAttachment.create()")
                    contentHandler(bestAttemptContent)
                    return
                }
                bestAttemptContent.attachments = [ attachment ]
            }
            contentHandler(bestAttemptContent)
        }
    }


extension UNNotificationAttachment {

    /// Save the image to disk
    static func create(imageFileIdentifier: String, data: NSData, options: [NSObject : AnyObject]?) -> UNNotificationAttachment? {
        let fileManager = FileManager.default
        let tmpSubFolderName = ProcessInfo.processInfo.globallyUniqueString
        guard let tmpSubFolderURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(tmpSubFolderName, isDirectory: true) else { return nil }

        do {
            try fileManager.createDirectory(at: tmpSubFolderURL, withIntermediateDirectories: true, attributes: nil)
            let fileURL = tmpSubFolderURL.appendingPathComponent(imageFileIdentifier)
            try data.write(to: fileURL, options: [])
            let imageAttachment = try UNNotificationAttachment(identifier: imageFileIdentifier, url: fileURL, options: options)
            return imageAttachment
        } catch let error {
            print("error \(error)")
        }

        return nil
    }

}

在让标记帮助器呈现元素之前,是否可以将ViewData [&#34; AspFor&#34;]值渲染到asp-for属性中?

0 个答案:

没有答案