nsabiyera / Oak

Frictionless development for ASP.NET MVC single page web apps. Prototypical and dynamic capabilities brought to C#.
http://amirrajan.github.com/Oak
MIT License
6 stars 7 forks source link

Heres Oak.Hidden input type #14

Open jakejscott opened 11 years ago

jakejscott commented 11 years ago
@helper Hidden(string name)
{
    @Hidden(new Oak.ElementMetaData(name))
}

@helper Hidden(string name, string value)
{
    @Hidden(new Oak.ElementMetaData(name, value))
}

@helper Hidden(Oak.ElementMetaData metaData)
{
    <input type="hidden" id="@metaData.Id()" name="@metaData.Id()" value="@metaData.Value()"@Attributes(metaData)@Styles(metaData)/>
}
amirrajan commented 11 years ago

What are your thoughts on the razor templates? Useful?

jakejscott commented 11 years ago

Yeah they are cool, easy to tweak too. Would be nice to have some way to hook up validation metadata. That way the helpers could also add a validation error css class like mvc does.

I also post to the server, and if there is a validation error, stash the @params into the temp and then reload that out on action executing using the following code in my base controller. Would need to add the validation errors into that I think...

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
  var flash = TempData["Flash"] as string;
  if (flash != null)
  {
    ViewBag.Flash = flash;
  }
  var @params = TempData["Params"] as dynamic;
  if (@params != null)
  {
    ViewBag.Params = @params;
  }
}

protected override void OnResultExecuting(ResultExecutingContext filterContext)
{
  if (filterContext.Result is RedirectResult || filterContext.Result is RedirectToRouteResult)
  {
    var flash = ViewBag.Flash as string;
    if (flash != null)
    {
      TempData["Flash"] = flash;
    }
    var @params = ViewBag.Params as dynamic;
    if (@params != null)
    {
      TempData["Params"] = @params;
    }
  }
}

And then in the controller

[HttpGet]
public ActionResult Index()
{
  if (ViewBag.Params == null)
  {
    ViewBag.Params = new { Email = "" };
  }

  return View();
}

[HttpPost]
public ActionResult Index(dynamic @params)
{
  dynamic invitation = new Invitation(@params);

  if (invitation.IsValid())
  {
    invitation.Send();

    return RedirectToAction("Sent");
  }

  ViewBag.Flash = invitation.FirstError();
  ViewBag.Params = @params;

  return RedirectToAction("Index");
}
amirrajan commented 11 years ago

Keep in mind that you also have an Errors method on the invitation class which returns a List<KeyValuePair<string, string>>. You could hydrate a list of errors off of that. I do a lot of work with dhtml and javascript, so the html helpers side of Oak hasn't gotten much attention. Definitely open to useful ways to represent error data.

jakejscott commented 11 years ago

Yeah agree using ajax and something like backbone is probably what everyone is doing these days. It is still nice to have for when your just chucking something together quickly I will have a muck around and see if I can get something working using the Errors collection. Cheers!

Hey I have another quick question surrounding Oak... have you had a go at using RavenDB, you could cut down on even more code... get rid of all the create table scripts for example. Also Raven supports in memory mode for when you want to run unit tests!

amirrajan commented 11 years ago

That is definitely on my list of things to do! I want to create a Gemini hook for dapper, raven, et al. It would be extremely useful for these providers to return an instance of Gemini as opposed to ExpandoObject and would open up a whole slew of cool functionality.