by
26. July 2010 18:51
Consider the following parent page Index.aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<HomeData>" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<div style="background-color:Red;">
<% Html.RenderAction("SignUp", "Account"); %>
</div>
</body>
</html>
Notice the RenderAction for the following SignUp.ascx page.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SignUpData>" %>
<% using (Html.BeginForm("SignUp", "Account"))
{ %>
<div>
<%: Html.LabelFor(m => m.Email) %>
</div>
<div>
<%: Html.TextAreaFor(m => m.Email) %>
</div>
<div>
<%: Html.ValidationMessageFor(m => m.Email) %>
</div>
<br />
<input type="submit" />
<%} %>
My SignUpData model looks something like this:
public class SignUpData : BaseViewData
{
/// <summary>
/// The email address you are signing up with.
/// </summary>
[DataType(DataType.EmailAddress)]
[Required(ErrorMessage = "Email is required.")]
[StringLength(200, ErrorMessage = "Email must be 200 characters or less.")]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Valid Email Address is required.")]
[DisplayName("Email Address")]
public string Email
{
get;
set;
}
...
My controller AccountController looks something like this:
[HttpPost]
public ActionResult SignUp(SignUpData data)
{
if (ModelState.IsValid)
{
return View("SignUp", data);
}
return RedirectToAction("Index", "Home", data);
//return View();
}
The problem I have is that although this all renders nicely when i enter an invalid email, it *does* set the ModelState as invalid and if u use Ajax i can get things working nicely.
However, I want this to work on the server too. I'm not sure whether there is NOW any way to pass this invalid model state such that the original Index page (top) is rendered with the RenderPartial called such that the invalid email address state is passed in and rendered - i just don't see the best practice way (sure, i can think of 50 hacks) to get the error information back on the postback (ideally it would work OOTB as it does normally).
I also disable Session state in my applications so i can't use TempData.
by
23. July 2010 02:15
Today I enjoyed a session (technically i'm still listening) by Phil Haack of Microsoft at the Virtual MVC conference discussing MVC 3. He discussed Global Filter providers which will enable you to apply a filter attribute to a number of controllers in pretty much a single line of code. He also showed Conditional Filters which can be used to conditionally apply a filter based on some code check (his example was a check as to whether we were in debug mode).
I have been working with filters today and it solved something i was thinking about today. I like the idea of extending it and i suspect that (and i don't know any more about them than what i saw on the slides) conditional filters *may* solve a number of things i'd like to be able to do.
So I asked a question about using RegEx and patterns with the filters. What I mean by that is being able to read the metadata of the controller classes and methods and being able to apply filters conditionally to them.
For example:
- Apply a trace filter to an methods marked with [HttpPost]
- Apply a debug filter whenever a method in the "AccountController" or "ProfileContoller" is called.
- ... even apply a debug filter whenever a method called "Save" is called in the "AccountController" or "ProfileContoller" is called.
These are some basic examples, but with the ability to apply global filters combined with an ability to read metadata on controllers, methods and so on (and perhaps even the state of the user or application) you can imagine a host of neat filters that could be quickly added to your code.
Further, being able to specify these rules declaratively and using a declarative service locator technique to accomplish DI for your filters could mean it would be super easy to attach filters to your applications without recompiling.
by
8. July 2010 15:52
The EF4 bits are excellent but one of the pains i have had was how to use the EF designer and add a foreign key mapping to an entity. So you have a User entity and an Address entity and the Address entity has a UserId foreign key that links to the User Id property.
I kept running into an issue that said the Address entity wasn't mapped and specifically the foreign key. I had no idea what to do to solve this. I checked the Xml behind the EDMX and found that not storage model had been created to allow that mapping. This seems odd to me. I would think it would create it when you are working in the designer and make the update upon commit!?
Anyway, the resolution to this is to right-click the model and say Generate Database from Model. This creates the data scripts and once executed it creates the tables in your database and at the same time updates you entity model to allow the mapping to happen. All works after that.
by
8. May 2010 23:32
If you want to navigate between screens in SketchFlow you can put this class at the top level in your namespace and it will do the bulk of the work for you. The code also details the meaning of the parameters you need to pass in to make it work.
/// <summary>
/// A global navigator instance that allows programmatic
/// navigation between screens in SketchFlow.
/// </summary>
public static class Navigator
{
/// <summary>
/// Adds a navigation option to the global navigator.
/// </summary>
/// <param name="target">The namespace qualified name of the page we are navigating to.</param>
/// <param name="eventname">The name of the event to watch for in the "obj" parameter</param>
/// <param name="obj">The object, such as a button.</param>
public static void Add(string target, string eventname, DependencyObject obj)
{
// Create a navigation instance of the screen we are navigating to
Microsoft.Expression.Prototyping.Behavior.NavigateToScreenAction navigateAction
= new Microsoft.Expression.Prototyping.Behavior.NavigateToScreenAction();
navigateAction.TargetScreen = target;
// create a trigger to fire the action
System.Windows.Interactivity.EventTrigger clickTrigger
= new System.Windows.Interactivity.EventTrigger(eventname);
clickTrigger.Actions.Add(navigateAction);
// associate the trigger with the object
System.Windows.Interactivity.TriggerCollection triggerCollection
= System.Windows.Interactivity.Interaction.GetTriggers(obj);
triggerCollection.Add(clickTrigger);
}
}
To use it, you can put this after InitializeComponent(); in the class on the screen you are invoking the action from.
Navigator.Add("MyScreens.Screen_1_4", "Click", this.MyButton);
by
24. April 2010 23:04
Myself and the kids made an animation at the Glasgow Science Centre - pretty basic but with a 3yr old and 7yr old was happy to get anything! Link below:
Glasgow Science Centre Animation (MP4 at 300k)
You really need to go see the Glasgow Science Centre. Amazing new exhibts.
5e3f9690-aa8b-4159-bcea-fa03b9e086ae|0|.0
Tags:
family
by
10. April 2010 15:38
I've heard oData uses quite a lot recently but been too bust to check it out. Well, now i've torn ligaments in my leg i'm getting time to read some of this stuff.
So, oData (Open Data Protocol) "provides a way to unlock your data and free it from silos that exist in applications today". An excellent example of its usage was demonstrated by Scott Hansleman where oData could be served from StackOverflow allowing developers to write oData queries directly against the Xml that is returned. Applying this idea to Twitter you may have something like this.

It got me thinking however - this is very powerful stuff and in many cases perhaps too powerful. There is a lot to be said in encapsulating functionality such as this being API's - it's easy to document, easy for developers to follow and the various flows required for an experience with the data provider can be optimized.
However, there is a very
powerful middle ground you don't really get with many of the API's today. With oData you could allow others to write the API's that interact with your system. So, if your system is an oData provider you can have several other developers who understand your data well enough that they can write various API's against your data to expose a host of different kinds of services. This is different from the current model - popularized in Twitter et al - whereby all people write against a strict API and doing anything out of the box (or a bug) requires waiting for Twitter to fix their API.
In the oData model you can have many API's and you choose the one that works for you. Something like this.

by Administrator
4. April 2010 15:53
StartMeme provides social start pages on the web and includes streams from those sources. The idea is to collect together excellent sites into collections, or memes, proving a quick start to getting to different kinds of sites - whether you know the sites or not. Early days and i find it useful.

by Administrator
24. January 2010 09:00
If you see this post it means that BlogEngine.NET 1.6.0 is running and the hard part of creating your own blog is done. There is only a few things left to do.
Write Permissions
To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder.
If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts. If you are interested in using Microsoft SQL Server, MySQL, VistaDB, or other databases, please see the BlogEngine wiki to get started.
Security
When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password. Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.
Configuration and Profile
Now that you have your blog secured, take a look through the settings and give your new blog a title. BlogEngine.NET 1.4 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable. Be sure to fill in your author profile to take better advantage of this.
Themes and Widgets
One last thing to consider is customizing the look of your blog. We have a few themes available right out of the box including two fully setup to use our new widget framework. The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in. Be sure to check out our home page for more theme choices and downloadable widgets to add to your blog.
On the web
You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.
Good luck and happy writing.
The BlogEngine.NET team
c3b491e5-59ac-4f6a-81e5-27e971b903ed|5|4.2
Tags: blog, welcome