I have a SubmitComment
Action and a Message
class. I want to use Message
class for sending that the action is done successfully or not, but Message.Result
is false and Message.Text
is null when I check them in ShowProduct
action.
public class Message
{
public bool Result { get; set; }
public string Text { get; set; }
}
My SubmitCommen
t Action:
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 });
}
}
My ShowProduct
Action:
public ActionResult ShowProduct(int? id, message)
{
ViewBag.Message = message;
var model = storesDB.Products;
return View(model);
}
What's the problem?