我使用以下函数删除表中的行
//delete individual row
jQuery('.stdtable img.delete').click(function(){
var c = confirm('Continue delete?');
if(c) jQuery(this).parents('tr').fadeOut(function(){
jQuery(this).remove();
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
此代码位于单独的js文件中,并且对所有页面都是通用的.现在我想添加一个Ajax操作,删除数据库中的行.但是根据我所在的页面,它必须调用不同的控制器.
示例:产品页面必须在ProductController中调用delete,ProductGroup页面必须在ProductGroupController中调用delete
怎么办呢?
我需要为我的api控制器设置自定义操作,例如api/{controller}/{action}/{id}
这是我的配置
config.Routes.MapHttpRoute(
name: "DefaultMethodApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "Browse", id = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
这达到默认路由/ api/dropzone/1但是我尝试通过"ApiByAction"配置命中/ api/dropzone/browse/1,但它不起作用.
以下代码给出了无效的强制转换操作.我的MS Sql服务器中的Qty列是类型decimal(10,2)
#region SQL Syntax
var sql = "select qty from productarticle where articleid=@articleid and productid=@productid";
#endregion
using (IDbConnection cn = Connection)
{
cn.Open();
return cn.Query<double>(sql, new { articleid = articleid, productid = productid }).Single();
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试将其归还int,则没有问题.任何线索?
我使用EWS托管API在我的c#项目和我们的Exchange 2010服务器之间进行通信.我使用此代码从现在起和三天前收到收件箱中的所有邮件.
var ews = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ews.Credentials = new NetworkCredential(usr, psw, dmn);
ews.AutodiscoverUrl(url);
PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView view = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults;
view.PropertySet = itempropertyset;
do
{
findResults = ews.FindItems(WellKnownFolderName.Inbox, view);
foreach (Item item in findResults.Items)
{
if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue;
item.Load(itempropertyset);
var message = EmailMessage.Bind(ews, item.Id,
new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments));
string to = message.ToRecipients[0].Address.ToLower();
string body = item.Body;
}
view.Offset += findResults.TotalCount;
} while (findResults.MoreAvailable);
Run Code Online (Sandbox Code Playgroud)
现在问题.我想改进这一行, if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue;因为当我使用它时,api从收件箱中获取所有消息,如果它比旧的那么三天就继续.我想在代码中先前指定此过滤器,因此api不必处理所有消息.