I think you can't use "print" to return any value You have to use "select" instead:
SELECT 'AMOUNT MUST BE A VALUE BETWEEN 0 AND 50'
Then when run insert query, be sure that you execute commend by use ExecuteScalar.
But I don't prefer above solution, while you are using MVC4 please use data annotation as below :
On the class file of the Book, make use for data annotations:
using System.ComponentModel.DataAnnotations;
And change the field declaration to :
[Range(0,50,ErrorMessage="Amount must be between 0 and 50")]
public int Amount { get; set; }
Now on the view add this after Amount field:
@Html.ValidationMessageFor(model => model.Amount, "", new { @class = "text-danger" })
And in your controller you must check if the current ModelState is valid.
public ActionResult Post(CreateBook book)
{
if (ModelState.IsValid) // this will check your model for validations like range, required and so on
{
}
}
More reading here: https://msdn.microsoft.com/en-us/library/dd901590%28VS.95%29.aspx?f=255&MSPPError=-2147217396
And about validation using data annotations here: http://www.asp.net/mvc/overview/older-versions-1/models-%28data%29/validation-with-the-data-annotation-validators-cs
And get rid of that trigger. Non-validated data mustn't get throught your business to the database.