PDA

View Full Version : FormPanelForModel with DateTime property



VSirchenko
Aug 04, 2014, 1:04 AM
Hello All

I want to create FormPanelForModel, I show this panel in Window. Model is which I show in FormPanel has DateTime
When I try to open window I get Error

This is Model:


public class ExRate
{
[HiddenInput(DisplayValue = false)]
public Int32 ID { get; set; }

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public DateTime Date { get; set; }

[HiddenInput(DisplayValue = false)]
public Int32 CurrencyID { get; set; }

[ForeignKey("CurrencyID")]
[Display(Name = "Валюта")]
[UIHint("Currency")]
public virtual Currency Currency { get; set; }

//[DataType(DataType.Currency)]
public float Rate { get; set; }

public ExRate()
{
ID = 0;
Date = DateTime.Now;
CurrencyID = 0;
Rate = 0;
}
}

This is View:


@(Html.X().Window()
.ID("wndExRate")
.Title(ViewBag.Title)
.Width(400)
.Height(122)
.Plain(true)
.Layout(LayoutType.Fit)
.Items(Html.X().FormPanelForModel()
.BodyPadding(5)
.DefaultAnchor("100%")
.Buttons(Html.X().Button()
.Text("Сохранить")
.DirectClickUrl(Url.Action("Create"))
)
)
)

This is Error:
An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code
Additional information: String was not recognized as a valid DateTime.

Daniil
Aug 04, 2014, 12:22 PM
Hi @VSirchenko,

Welcome to the Ext.NET forums!

Please clarify do you pass a Model instance to the View from the Controller?

VSirchenko
Aug 04, 2014, 2:58 PM
Yes, I do

This is a Controller:

public class ExRateController : Controller
{
private WebMFAContext db = new WebMFAContext();

//
// GET: /ExRate/

public ActionResult Index()
{
return new Ext.Net.MVC.PartialViewResult { ViewName = "Index" };
}

This is View:

@model Models.Data.ExRate

@(Html.X().Window()
.ID("wndExRate")
.Title("ExRate")
.Width(400)
.Height(122)
.Plain(true)
.Layout(LayoutType.Fit)
.Items(Html.X().FormPanelForModel()
.BodyPadding(5)
.DefaultAnchor("100%")
.Buttons(Html.X().Button()
.Text("Сохранить")
.DirectClickUrl(Url.Action("Create"))
)
)
)

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

Daniil
Aug 05, 2014, 2:23 PM
Do you mean this?

@model Models.Data.ExRate

I would not say you pass a Model instance here, you just declare its type.

ForModel() helpers are supposed to deal with a real Model instance.

VSirchenko
Aug 05, 2014, 3:38 PM
Sorry, but what exactly I have to do?

Daniil
Aug 05, 2014, 3:47 PM
Probably, pass a Model instance with a PartialViewResult?

VSirchenko
Aug 05, 2014, 3:50 PM
Can you write me an example?

Daniil
Aug 06, 2014, 8:17 AM
I would try this

new Ext.Net.MVC.PartialViewResult { ViewName = "Index", Model = new Models.Data.ExRate() };

VSirchenko
Aug 06, 2014, 3:10 PM
Thank you it's working, but I have some problem with style

14021

14031

I have 2 chance to select Date

Daniil
Aug 07, 2014, 10:21 AM
Please provide a test case.

VSirchenko
Aug 09, 2014, 8:18 PM
this's example

geoffrey.mcgill
Aug 09, 2014, 11:53 PM
Please simplify your sample as much as possible and post as text inside [CODE] tags within a forum post.

VSirchenko
Aug 11, 2014, 1:55 AM
I try to add link to my example, but it was deleted by someone

VSirchenko
Aug 11, 2014, 2:27 AM
this is my example

VSirchenko
Aug 11, 2014, 4:47 AM
I also have problem with show date in grid, it's also can look at example

geoffrey.mcgill
Aug 11, 2014, 7:12 AM
Please post your simplified sample directly into your forum post inside [CODE] tags.

We will remove all external links to .rar and .zip files, and in general we will remove all external links.

VSirchenko
Aug 11, 2014, 2:10 PM
I can't use [CODE], because may be something wrone with project and I give you link on project

geoffrey.mcgill
Aug 11, 2014, 4:26 PM
Unfortunately we do not accept full project submissions. You'll need to simplify your sample down to the minimum required to reproduce the problem, then post that code sample into a forum post inside [CODE] tags.

You can review the following Forum Guidelines before post in the forums again:

http://forums.ext.net/showthread.php?3440-Forum-Guidelines-For-Posting-New-Topics (http://forums.ext.net/showthread.php?3440-Forum-Guidelines-For-Posting-New-Topics)

http://forums.ext.net/showthread.php?10205-More-Information-Required (http://forums.ext.net/showthread.php?10205-More-Information-Required)