asp.net mvc 3 - Show foreign key relation message when deleting records in mvc3 -
i have table country.countryid foreign key on table energy.when try delete record in country table,i should message showing foreign key relation. message should display name of child tables.i have used jtable.
edit: model is:-
public class country { [key, databasegenerated(databasegeneratedoption.identity)] public int countryid { get; set; } [required(errormessage = "the country name required")] public string countryname { get; set; } } public class energy { [key, databasegenerated(databasegeneratedoption.identity)] public int energyid { get; set; } [required(errormessage = "country required.")] public int? countryid { get; set; } [foreignkey("countryid")] public virtual country countries { get; set; } }
inside controller have written this:-
sqlexception sqlexception = ex.innerexception != null ? ex.innerexception.innerexception sqlexception : null; if (sqlexception != null) return json(new { result = "error", message = "sorry! unable delete." }); else return json(new { result = "error", message = ex.message });
how related table names in mvc3?? possible using linq??
Comments
Post a Comment