I'm running the app in this Microsoft Tutorial and when I try to enter a url in the input box of the app (for instance, http://msdn.com
or http://blogs.msdn.com/adonet
as shown in the tutorial) and click submit I get the following validation error:
The value 'http://msdn.com' is not valid for Url.
When I debug the application I notice that in the following code of the tutorial the ModelState.IsValid value is showing as 'false'. What is missing here and how can it be fixed?
public IActionResult Create(Blog blog)
{
if(ModelState.IsValid)
{
_context.Blogs.Add(blog);
_context.SaveChanges();
return RedirectToAction("Index");
}
return View(blog);
}
Points to note:
- I'm using latest ASP.NET Core 1.0 and VS2015-Update 3 [released on June 27, 2016] on windows 8.1
- In the Creat.chtml view of the tutorial,
<input asp-for="Url" class="form-control" />
was initially showing as readonly so I added type="text" attribute there and it became read/write - My app is an exact copy of the tutorial (I did copy/past) except that instead of choosing 'No Authentication' I chose 'Individual User Accounts' option when creating the poroject. But that, I think, should not make any difference.
UPDATE
I added var errors = ModelState.Values.SelectMany(v => v.Errors);
just above if(ModelState.IsValid)
statement and I see the following in the debug window showing the values of error collection
but can't figure out the cause of error. Maybe. someone can help:
UPDATE 2:
I found my mistake. I was using int datatype in public int Url { get; set; }
property of the Blog class instead of using string. Changed it to string and it's working now. Someone may help what the error in image is saying.