Hi Girish, sorry but i did’t understand, are you saying why I have not used HTML Hepers and used Tag helpers in view or something else. Can you provide some examples so that I can understand what exactly you want to know?
Girish, Tag helpers are more cleaner than HTML helpers, these are HTML friendly and who ever have worked on HTML can work with tag helpers with little knowledge. You can refer below document to get more detail on this
Hello,
I’m using core 3. When I implement the delete operation (Get). The Url in browser address bar encoded / to %2F ( /Make/Delete%2F5 ). And delete action will not invoke. If I change the URL in the browser to /Make/Delete/5 it is working perfectly. How my application will solve the URL even it is encoded.
Probles:-
public IActionResult Delete(int id)
{
Model model = _db.Models.Find(id);
if(model==null)
{
return NotFound();
}
_db.Models.Remove(model);
or
_db.Remove(model); // it’s working but not delete item properly something wrong
_db.SaveChanges();
return View(nameof(Index));
}
Wrong- >
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml, line 35
Stack Query Cookies Headers
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml
+
@foreach (var item in Model)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Probles:-
public IActionResult Delete(int id)
{
Model model = _db.Models.Find(id);
if(model==null)
{
return NotFound();
}
_db.Models.Remove(model);
or
_db.Remove(model); // it’s working but not delete item properly something wrong
_db.SaveChanges();
return View(nameof(Index));
}
Wrong- >
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml, line 35
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml
+
@foreach (var item in Model)
Hi Sir,
Why did’t you use Html Helpers Methods for CRUD operations on views?
Thanks & Regards,
Girish
Hi Girish, sorry but i did’t understand, are you saying why I have not used HTML Hepers and used Tag helpers in view or something else. Can you provide some examples so that I can understand what exactly you want to know?
Thank You Sir for replying…Yes Sir why you did not used Html Helpers Method instead you use Tag Helpers?
Girish, Tag helpers are more cleaner than HTML helpers, these are HTML friendly and who ever have worked on HTML can work with tag helpers with little knowledge. You can refer below document to get more detail on this
https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro?view=aspnetcore-2.2
Hello,
I’m using core 3. When I implement the delete operation (Get). The Url in browser address bar encoded / to %2F ( /Make/Delete%2F5 ). And delete action will not invoke. If I change the URL in the browser to /Make/Delete/5 it is working perfectly. How my application will solve the URL even it is encoded.
Hi Ajith, are you getting this problem after converting link from anchor tag to Input type button or you are getting this problem with anchor tag?
hi,
the delete will throw an error as it encodes the url to /Make/Delete%2F5
The code for delete should be Delete and it will pick it up
Hi Sandeep,
Is having the same problem that the routing system seems could not handle URL that is urlended.
https://localhost:44390/Make/Delete%2F2
If I changed to https://localhost:44390/Make/Delete/2 it worked!
The view has:
Delete”
Any suggestions?
Thanks,
After using Post to do delete, using rather than , it worked.
But, still wonder why with @url.Action(…) and urlencoded did not work.
Hi, Sir
Probles:-
public IActionResult Delete(int id)
{
Model model = _db.Models.Find(id);
if(model==null)
{
return NotFound();
}
_db.Models.Remove(model);
or
_db.Remove(model); // it’s working but not delete item properly something wrong
_db.SaveChanges();
return View(nameof(Index));
}
Wrong- >
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml, line 35
Stack Query Cookies Headers
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml
+
@foreach (var item in Model)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Hi, Sir
Probles:-
public IActionResult Delete(int id)
{
Model model = _db.Models.Find(id);
if(model==null)
{
return NotFound();
}
_db.Models.Remove(model);
or
_db.Remove(model); // it’s working but not delete item properly something wrong
_db.SaveChanges();
return View(nameof(Index));
}
Wrong- >
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml, line 35
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Model_Index.ExecuteAsync() in Index.cshtml
+
@foreach (var item in Model)