c# - 列出 ASP.NET MVC 中的资源记录
问题描述
我正在尝试从表中的记录集中列出资源记录。我可以显示所有资源记录,但我需要的是它只显示传递给 ActionResult 的记录集的资源记录。
澄清一下,我有一个 RecordSet 视图,其中包含托管区域中所有记录集的表,当有人单击它旁边的字段时,它会获取该记录集的名称并将其作为值(字符串答案)传递给ResourceRecords 控制器。然后它使用它来设置StartRecordName
. 之后我MaxItems
设置为 1。所以这基本上是搜索功能。这有效,除非有多个资源记录集命名为相同的东西,它不会列出它们的记录。它只取第一个资源记录集记录。
这是我在控制器中的内容:
public ActionResult ResourceRecords(string answer)
{
//create Route 53 Client using the credentials
IAmazonRoute53 route53Client = new AmazonRoute53Client("AccessKey", "SecretKey", RegionEndpoint.USEast1);
// This gives us an object of this type: https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Route53/TListResourceRecordSetsResponse.html
var response = route53Client.ListResourceRecordSets(new ListResourceRecordSetsRequest
{
HostedZoneId = "HostedZoneId",
StartRecordName = answer,//start with the record set from the value passed in ResourceRecordSets.cshtml
MaxItems = "1"
});
//List for RecordSets and Resource Records
List<String> recordSetQuery = new List<String>();
List<String> resourceRecordQuery = new List<String>();
foreach (var recordset in response.ResourceRecordSets)
{
//add the record set name to the List
recordSetQuery.Add(recordset.Name);
foreach (var resourceRecord in recordset.ResourceRecords)
{
if (ModelState.IsValid && !String.IsNullOrWhiteSpace(answer))
if (recordSetQuery.Contains(answer))//find the value in the query(the resource record set List)
{
resourceRecordQuery.Add(resourceRecord.Value);
}
}
}
ViewBag.Test = resourceRecordQuery;
}
return View();
}
这是视图中的内容:
<table class="table table-striped table-bordered table-hover table-condensed">
<td colspan="2">Resource Record</td>
@foreach (var Records in ViewBag.Test)
{
<tr>
<td>
@Records
</td>
<td>
<button>Edit</button>
</td>
</tr>
}
</table>
这是我第一次这样做,所以我还在学习,我可能会让它变得更难,所以任何帮助都会很好。如果我没有发布所有需要的东西,请告诉我,我会发布它。我不想用不需要的代码淹没帖子。
解决方案
推荐阅读
- java - How to fetch and read a JSON file located on server?
- php - i have same column name of first_name in database and have different user_type how to separated show in the two different column of site
- python - Algorithm idea for pandas python
- java - 如何用另一个数组中的对象初始化一个新数组(我得到的是地址,而不是值)
- postgresql - Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”? in Odoo
- elasticsearch - Elasticsearch monitoring settings
- ios - 我想要自定义的 UITextfield,它具有与 android 相同的占位符行为,我也想要 UITextfield 中的错误标签
- phpstorm - PhpStorm is not opening on my Ubuntu 14.04
- iphone - 屏幕冻结,需要重新启动才能快速制作可点击的屏幕
- selenium - 使用封闭标记下方的文本查找 XPath