我将2个可空参数传递给Products操作。但是我被迫在mallId
中传递一些值,否则我会收到no route table matches found
错误。我想在null
中传递mallId
并在Products
行动中接收。
return RedirectToRoute("Products",
new
{
mallId =(Int32?)null,
storeId =(Int32?)storeProducts.StoreId
});
[Route("Mall/{mallId?}/Store/{storeId?}/Products", Name = "Products")]
public ActionResult Products(string mallId, long? storeId)
{
return View(products);
}
属性路由正在破解我的头脑,但它也很棒。
答案 0 :(得分:2)
# First, vectorize function
rottenrate <- function(movie){
require(RJSONIO)
link <- paste("http://www.omdbapi.com/?t=", movie, "&y=&plot=short&r=json&tomatoes=true", sep = "")
jsonData <- fromJSON(link)
return(jsonData)
}
vrottenrate <- Vectorize(rottenrate, "movie", SIMPLIFY = FALSE)
# Now, query and combine
movies <- c("inception", "toy story")
df <- do.call(rbind, lapply(vrottenrate(movies), function(x) as.data.frame(t(x), stringsAsFactors = FALSE)))
dplyr::glimpse(df)
# Observations: 2
# Variables:
# $ Title (chr) "Inception", "Toy Story"
# $ Year (chr) "2010", "1995"
# $ Rated (chr) "PG-13", "G"
# $ Released (chr) "16 Jul 2010", "22 Nov 1995"
# $ Runtime (chr) "148 min", "81 min"
# $ Genre (chr) "Action, Mystery, Sci-Fi", "Animation,
# ...
并且不传递mallId的值
答案 1 :(得分:2)
您应该为mallId提供默认值。分配参数的方式使得无法在路径组合中提供mallId:
[Route("Mall/{mallId=all}/Store/{storeId?}/Products", Name = "Products")]
public ActionResult Products(string mallId = "all", long? storeId = null)
{
if(mallId == "all")
//do something
return View(products);
}