这里我想从 the 返回custom action filter而不执行controller action methodin asp.net core WEB API。
以下是我对样品的要求code。
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
bool valid=SomeMethod();
if(valid)
//executes controller action
else
//returns without executing controller action with the custom message (if possible)
}
Run Code Online (Sandbox Code Playgroud)
我搜索并找到了一些相关的问题和答案,但没有任何对我有用。
找到了这个await base.OnActionExecutionAsync(context, next);,但它跳过了剩余的逻辑filters并直接执行,controller action所以对我的场景不起作用。
c# custom-action-filter action-filter onactionexecuting asp.net-core-mvc
我已经搜索了很多使用 向父菜单添加活动类的信息javascript。
我发现了更多示例,但没有一个适合我,下面是我的代码
超文本标记语言
<div id="menu1" class="hmenu">
<ul>
<li><a href="#">Item1</a>
<ul>
<li><a href="#">SubItem1</a>
<ul>
<li><a href="#">SubSubItem1</a></li>
<li><a href="#">SubSubItem2</a></li>
</ul>
</li>
<li><a href="#">SubItem2</a> </li>
<li><a href="#">SubItem3</a>
<ul>
<li><a href="#">SubSubItem1</a></li>
<li><a href="#">SubSubItem2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Item2</a></li>
<li><a href="#">Item3</a>
<ul>
<li><a href="#">SubItem1</a>
<ul>
<li><a href="#">SubSubItem1</a></li>
<li><a href="#">SubSubItem2</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<br style="clear: left" />
</div>
Run Code Online (Sandbox Code Playgroud)
我的要求是当我单击SubItem1时, Item1和SubItem1都应该处于活动状态。
当我单击SubSubItem1时,SubSubItem1、SubItem1和Item1应该处于活动状态。
意味着当单击任何链接时,其所有父链接和同一链接都应处于活动状态。
我尝试过使用这段javascript代码:
$(document).ready(function () { …Run Code Online (Sandbox Code Playgroud) 在class我已经声明了property如下所示
class MyClass
{
public string TName
{
get {return "";}
}
// and some other properties ....
}
Run Code Online (Sandbox Code Playgroud)
一种方法是返回类型IEnumerable<MyClass>,这里我想得到TName值
Name 1, Name 2, Name 3, Name 4........
Run Code Online (Sandbox Code Playgroud)
根据计数.
问题:
如何在我的上述属性的方法中增加计数器的值setter,以便我可以追加像"Name" + counter;
或者有没有其他更好的方法来实现这一目标,looping而fetching不是计数DB.
先感谢您.
我正在写custom filter我的内容Web API,我想修改方法ActionExecutedContext内部的结果OnActionExecuted。
我得到的结果类型与返回的OkObjectResult一样。action methodIActionResult
public void OnActionExecuted(ActionExecutedContext context)
{
var myResult = context.Result;
//Type of myResult is OkObjectResult
}
Run Code Online (Sandbox Code Playgroud)
那么这里我如何将其转换OkObjectResult为我的模型Object,以便我可以使用properties并操作这些值。
感谢任何建议。
custom-action-filter onactionexecuted asp.net-core-webapi asp.net-core-2.1
我有一个List类型Test,其中有4个properties,List需要根据某些特定条件进行排序。以下是propertiesof class Test以及示例数据。
class Test
{
int order;
string value;
string dept;
//..... and some others
}
Run Code Online (Sandbox Code Playgroud)
样本json:
[
{
"order":3,
"value":"ABC",
"dept":"A"
},
{
"order":2,
"value":"XYZ",
"dept":"A"
},
{
"order":1,
"value":"ABC2",
"dept":"P"
},
{
"order":4,
"value":"XYZ2",
"dept":"P"
},
{
"order":6,
"value":"ABC3",
"dept":"Z"
},
{
"order":5,
"value":"XYZ3",
"dept":"Z"
},
]
Run Code Online (Sandbox Code Playgroud)
上面的json数据被加载到一个List<Test>。
我的要求是对上面的列表进行排序,就像首先使用dept=P,然后是dept=A,然后dept=Z第二种排序标准是order。
我尝试过,OrderBy(x=>x.dept).ThenBy(x=>x.order)但是输出不是预期的。
有什么方法可以指定dept …