菜鸟问题.我有一个参数传递给创建视图.我需要设置一个默认值的字段名称.@ Html.EditorFor(model => model.Id)我需要设置名为Id的输入字段,其默认值通过actionlink传递给视图.
那么,这个输入字段 - @ Html.EditorFor(model => model.Id) - 如何设置为默认值.
以下工作会怎样?数字5是参数,我传入文本字段以设置默认值.
@Html.EditorFor(c => c.PropertyName, new { text = "5"; })Run Code Online (Sandbox Code Playgroud) 我需要获取表行并转换为JSON.
有任何想法吗?我在这里有这个代码,但它不起作用.
function tableToJSON(tableID) {
return $(tableID + " tr").map(function (row) {
return row.descendants().pluck("innerHTML");
}).toJSON();
}
Run Code Online (Sandbox Code Playgroud) 是否有可能让OData执行以下操作?我希望能够通过传递可能不是主键的参数来查询REST调用.我可以调用REST方法,如 - > GetReports(22, 2014)或Reports(22, 2014)?
[HttpGet]
[ODataRoute("Reports(Id={Id}, Year={Year})")]
public IHttpActionResult GetReports([FromODataUri]int Id, [FromODataUri]int Year)
{
return Ok(_reportsRepository.GetReports(Id, Year));
}
Run Code Online (Sandbox Code Playgroud)
这是我的最新变化.
//Unbound Action OData v3
var action = builder.Action("ListReports");
action.Parameter<int>("key");
action.Parameter<int>("year");
action.ReturnsCollectionFromEntitySet<Report>("Reports");
Run Code Online (Sandbox Code Playgroud)
我的控制器ReportsController的方法
[HttpPost]
[EnableQuery]
public IHttpActionResult ListReports([FromODataUri] int key, ODataActionParameters parameters)
{
if (!ModelState.IsValid)
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
int year = (int)parameters["year"];
return Ok(_reportsRepository.GetReports(key, year).Single());
}
Run Code Online (Sandbox Code Playgroud)
我试着像这样调用网址:
http://localhost:6064/odata/Reports(key=5,year=2014)/ListReports
Run Code Online (Sandbox Code Playgroud)
没有找到与请求http://localhost:6064/odata/Reports(key%3D5%2Cyear%3D2014)/ListReports'URI'.` 匹配的HTTP资源
我收到以下错误:
控制器"客户端"中操作"GetClients"上的路径模板"GetClients()"不是有效的OData路径模板.找不到"GetClients"细分受众群的资源.
我的控制器方法看起来像这样
public class ClientsController : ODataController
{
[HttpGet]
[ODataRoute("GetClients(Id={Id})")]
public IHttpActionResult GetClients([FromODataUri] int Id)
{
return Ok(_clientsRepository.GetClients(Id));
}
}
Run Code Online (Sandbox Code Playgroud)
我的WebAPIConfig文件有
builder.EntityType<ClientModel>().Collection
.Function("GetClients")
.Returns<IQueryable<ClientModel>>()
.Parameter<int>("Id");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "odata",
model: builder.GetEdmModel());
Run Code Online (Sandbox Code Playgroud)
我希望能够像这样调用odata rest api:
http://localhost/odata/GetClients(Id=5)
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
c# odata asp.net-web-api asp.net-web-api-routing asp.net-web-api-odata
我在提交时验证的字段上有mvc属性.虽然这些属性在这些字段上,但是如果单击SaveDraft按钮,我想覆盖它们的验证.现在我尝试使用jquery规则禁用该字段的验证,但mvc属性似乎覆盖了规则.如果单击其他按钮,如何使MVC属性忽略验证?这是一个我想在onClick上做的例子,但它不起作用.
$(".btnsave").click(function () {
$('#WizForm').validate(
{
rules:
{
Title: false,
Description: false //dont validate this field onclick
},
}).Form();
});
Run Code Online (Sandbox Code Playgroud) 我在控制器中有以下内容.
$rootScope.$on('progressbarEvent', function (event, data) {
$rootScope.progresscurrent = data.currentprogress;
console.log('Event listening: ' + $rootScope.progresscurrent);
});
I have this in a factory service.
$rootScope.$emit('progressbarEvent', dataFactory.currentprogress);
Run Code Online (Sandbox Code Playgroud)
$ on返回undefined.谁知道这个的原因?
我的控制器是:
app.controller('indexcontroller', ['$rootScope','$scope', '$http', 'dataFactory',
function ($scope,$http,$rootScope, dataFactory) {
Run Code Online (Sandbox Code Playgroud) 我正在将entityManagerFactory注入Angular,但是我收到了一个错误.正如John Papa的例子一样,这在datacontext模块中完成.错误是未知的提供者.我在index.html文件中包含了entityManagerFactory.js文件但没有成功.有任何想法吗?
function () {
'use strict';
var serviceId = 'datacontext';
angular.module('app').factory(serviceId, ['common', 'entityManagerFactory', 'breeze', 'logger', datacontext]);
function datacontext(common) {
var $q = common.$q;
var service = {
getPeople: getPeople,
getMessageCount: getMessageCount
};
}
}
Run Code Online (Sandbox Code Playgroud)