我正在将View的视图模型从View传递到HttpPost
create动作。通常会创建一个新的数据库项目,但是RedirectToAction
不起作用。它进入索引动作,但不返回任何视图。我真的不知道为什么会发生这种情况,特别是因为没有错误显示,并且在其他创建操作(除了模型作为参数)上正常工作。
索引视图显示数据库中的所有销售。
索引操作:
public async Task<IActionResult> Index()
{
return View(await _context.Sells.ToListAsync());
}
创建操作:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(SellsViewModel sellsViewModel)
{
List<Product> tableProducts=new List<Product>();
foreach(Guid item in sellsViewModel.selectedProducts)
{
tableProducts.Add(_context.Products.FirstOrDefault(p => p.Id == item));
}
var sell = new Sell();
sell = sellsViewModel.sell;
sell.Id = Guid.NewGuid();
sell.Products = tableProducts;
_context.Add(sell);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
答案 0 :(得分:0)
假设重定向在您的方案中不起作用,如果您想使用 add_filter( 'get_the_archive_description', 'display_my_author_counter' );
function display_my_author_counter( $content ) {
// Is this an author page?
if ( is_author() ) {
// Global values picked up from my_author_counter().
global $post, $author_id, $author_counts;
/** This is where you'd manage the raw data ($author_counts) for display ($display_value). **/
// Handle raw $author_counts values for desired display.
// Start with an zero for our display value.
$display_value = 0;
// Our counter collects all visists by IP. Get only unique IP addresses.
$unique_counts = array_unique( $author_counts );
// Loop through the unique IP values and check the timestamp. Only get the last 7 days.
foreach ( $unique_counts as $timestamp => $ip ) {
if ( $timestamp > strtotime( '-7 day' ) ) {
// Increment the display count by 1.
$display_value++;
}
}
/** END manage the raw data ($author_counts) for display ($display_value ). **/
// Add the display count to the archive description.
$content = $content . "This author page has been viewed " . $display_value . " times";
}
return $content;
}
进行重定向,请在代码中执行以下操作:
Task