Asp.net mvc C#和Vue.js中的模型和数据注释
假设我有一个业务对象:(C#) 然后我有一个模型控制器:(C#) 我的问题是;如何从Vue组件访问注释“必需”和“MyCustomAttribute”以及其他注释。我应该在控制器中添加一个方法来获取这些属性吗Asp.net mvc C#和Vue.js中的模型和数据注释,asp.net-mvc,vue.js,model-view-controller,data-annotations,custom-attributes,Asp.net Mvc,Vue.js,Model View Controller,Data Annotations,Custom Attributes,假设我有一个业务对象:(C#) 然后我有一个模型控制器:(C#) 我的问题是;如何从Vue组件访问注释“必需”和“MyCustomAttribute”以及其他注释。我应该在控制器中添加一个方法来获取这些属性吗 [HttpPut("attributes")] public ActionResult<Attribute[]> Attributes(string propertyName) { return getAttributesOf(prope
[HttpPut("attributes")]
public ActionResult<Attribute[]> Attributes(string propertyName) {
return getAttributesOf(propertyName);
// getAttributesOf("str") would return Attribute[]{ RequiredAttribute, MyCustomAttribute(...)}
}
[HttpPut(“属性”)]
公共操作结果属性(字符串属性名称){
返回getAttributesOf(propertyName);
//getAttributesOf(“str”)将返回属性[]{RequiredAttribute,MyCustomAttribute(…)}
}
有更好的办法吗
[Route("api/[controller]")]
[ApiController]
public class ModelAController : Controller
{
// ... some contructors and readonly database ...
[HttpPut("read")]
public ActionResult<ModelA> Read() {
return db.Read<ModelA>();
}
}
import ...
export default {
data () {
return {
annotations: '',
model: '',
};
},
created: function()
{
this.values = Read('ModelA'); // reads data in json format returned by ModelAController.Read()
this.annotation = // ?????
},
};
[HttpPut("attributes")]
public ActionResult<Attribute[]> Attributes(string propertyName) {
return getAttributesOf(propertyName);
// getAttributesOf("str") would return Attribute[]{ RequiredAttribute, MyCustomAttribute(...)}
}