Filed in: ASP.MVC
Home » ASP
In Asp.Net Mvc, you can add an attribute to your controller or to some actions of your controller to tell Asp that you will take care of errors if they occur. You simply need to add the attribute HandleError.
[HandleError]
public class MyController : Controller
{
}
You can take care of specific error by specifying one or many type of exception that...
You may need to have the full url of an action in the case you desire to do some Javascript redirection. You may want to pass which url to redirect via Json. Using not a fully constructed url will fail the redirection. The trick is to pass a full url. Asp.Net MVC give you the possibility to generate a fully formed url with the URL helper. The class...
Filed in: ASP.MVC
It’s rare that I am writing about third party control but Telerik grid has a new feature that is kinda hard to find any way to implement. If you want to insert a new row to a Telerik ASP.Net MVC grid that you need to add a call to the method InsertRowPosition. This can be done inside the method Editable of the grid.
@Html.Telerik().Grid<YourObjectType>().Editable(e=>e.InsertRowPosition(GridInsertRowPosition.Bottom))
This...
Filed in: Telerik Asp.Net MVC
If you are using Html Helper to generate your form you may end up with label with the property name into it. You may also have error message with the property name. The problem is if your object contain English term, you would prefer not to show them in English if you write something in French.
public class Person
{
public string Name { get; set;...
Filed in: ASP.MVC
If you are using the Data Annotation with Asp.Net MVC you might need to localize the message from these annotation.
Here is an example:
public class Person
{
[Required(ErrorMessage="FirstName is required")]
public string FirstName { get; set; }
//...
}
If you want to have the Data Annotation translated in many languages, you...
Filed in: ASP.MVC
It’s possible to create a custom generic Html Extension Helper with the use of Expression Helper and if required the ModelMetadata to get the value.
public static string MyExtensionFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> property)
{
var meta = ModelMetadata.FromLambdaExpression(property,...
Tim Barcz, Matt Hawley, Stephen Walther and Scott Guthrie (VP at Microsoft and lead for many project like Entity Framework, Asp.Net, etc) have already discussed about this problematic and created the PRG pattern to solve this problem. In fact, to solve this problem you should not handle manually the ModelState but simply use Import and Export attribute...
If you are getting your Model from a form and you want to manipulate the data that came from the client form and write it back to a view, you need to call ModelState.Clear() to clean the ModelState values.
The reason is that normally, you want to postback to the client the form with all the errors. So, when you put back the parameter that contain your...
Filed in: ASP.MVC
They are a lot of way to validate model object in object oriented world. Most of the time, we see that we can check the information inside the Setter (which in C# is the SET of a property). This is interesting and personally my favorite way to do it. The main reason is that you never have any model object in a dirty state which could fail on future...
Filed in: ASP.MVC
You can compile any controller to have the same method name if they have different parameter type or numbers. This is normal in .Net framework but what MVC developer must know is that you cannot have 2 actions (which are methods) with the same name even if they doesn’t have the same parameter type. That mean you cannot have :
public ActionResult...
Filed in: ASP.MVC