I have a problem with calling my function that show the books for same author, for example I have a these authors :
Author Name : Jeremy McPeak; Joe Fawcett; Nicholas C. Zakas;
When I click on "Jeremy McPeak"
and "Joe Fawcett"
the new page opened well and show all the books for those authors .
But when click on this author "Nicholas C. Zakas"
and since he has a DOT in his name , I got exception
Object reference not set to an instance of an object.
This problem only when I click on any author that have a DOT In his name ..
also here is my function :
public ActionResult Author(string AuthorName, int? page)
{
if (AuthorName != null)
{
ViewBag.AuthorName = AuthorName;
int pageSize = 6;
int pageNumber = page ?? 1;
var result = db.Books.Where(s => s.Author_name.Contains(AuthorName)).OrderByDescending(x => x.Book_id).ToList();
return View(result.ToPagedList(pageNumber, pageSize));
}
return RedirectToAction("Index", "Home");
}
Author View Code:
@using PagedList.Mvc
@using System.Text.RegularExpressions;
@model PagedList.IPagedList<SmartBookLibrary.Models.Book>
@{
ViewBag.Title = "Books For " + ViewBag.AuthorName+ "- Smart Books Library";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section AdditionalMeta
{
<meta name="robots" content="index,follow">
}
<div class="container">
<!-- Page Header -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
<span class="fa fa-pencil"></span>@ViewBag.AuthorName
</h1>
</div>
</div>
<!-- /.row -->
<!-- Projects Row -->
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4 portfolio-item" style="margin-bottom:10px;height:450px">
<div class="ih-item square effect3 bottom_to_top">
<a href="~/book/@item.Book_id/@item.UrlSlug">
<div class="img"><img itemprop="image" class="img-responsive" src="~/Images/@item.Book_Image" alt="@item.Book_name" title="@item.Book_name"></div>
<div class="info">
<h3>@item.Book_name</h3>
</div>
</a>
</div>
<h3 itemprop="name">
<a href="~/book/@item.Book_id/@item.UrlSlug">
@item.Book_name
@if (item.Edition != 0)
{
switch (item.Edition)
{
case 1:<small class="btn btn-default btn-xs">@item.Edition'St Edition</small> break;
case 2:<small class="btn btn-default btn-xs">@item.Edition'nd Edition</small> break;
case 3:<small class="btn btn-default btn-xs">@item.Edition'rd Edition</small> break;
case 4 - 10:<small class="btn btn-default btn-xs">@item.Edition'th Edition</small> break;
default:<small class="btn btn-default btn-xs">@item.Edition'th Edition</small> break;
}
}
</a>
</h3>
<p itemprop="description">
@*@Html.Raw(item.Book_Description)*@
</p>
</div>
}
</div>
<!-- /.row -->
<hr>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Author", new { AuthorName = ViewBag.AuthorName, page }))
</div>
Calling Area :
@{
var s = Model.Book.Author_name.ToString();
string[] Auth = s.Split(',');
ViewBag.Author = Auth;
}
<p itemprop="author">
<i class="glyphicon glyphicon-pencil"></i> <b>Author Name :</b>
@for (int i = 0; i < Auth.Length; i++)
{
<a style="color:#777777" href="~/Author/@Auth[i]">@Auth[i];</a>
}
</p>
Any one know how to fix that ?