У меня есть действие SubmitComment
и класс Message
.Я хочу использовать Message
класс для отправки, если действие выполнено успешно или нет, но Message.Result
имеет значение false и Message.Text
равно нулю, когда я проверяю их в действии ShowProduct
.
public class Message
{
public bool Result { get; set; }
public string Text { get; set; }
}
Мое SubmitCommen
т Действие:
public ActionResult SubmitComment(int productId, string comment, string nickName)
{
try
{
var productCM = new ProductCM
{
//I make my prodcut comment object here
};
storesDB.ProductCMs.Add(productCM);
storesDB.SaveChanges();
Message message = new Message
{
Result = true,
Text = "Your comment successfully registered."
};
return RedirectToAction("ShowProduct", new { id = productId, message });
}
catch (//if any exeption happend)
{
Message message = new Message
{
Result = false,
Text = "Sorry your comment is not registered."
};
return RedirectToAction("ShowProduct", new { id = productId, message });
}
}
Мое ShowProduct
Действие:
public ActionResult ShowProduct(int? id, message)
{
ViewBag.Message = message;
var model = storesDB.Products;
return View(model);
}
В чем проблема?