mardi 25 avril 2017

Configure structure map to scan for all implementations as opposed to convention?

Currently have my structuremap set-up configured to scan for implementations via convention.

So for any dependency on IMyRepo, MyRepo will be looked for.

But how can I resolve IMyRepo to any implementation that doesn't follow that naming convention?

i.e. TotallyDifferentRepoImp : IMyRepo

Sorry - I should clarify, I want this to be automatically registered - i..e I don't want to have to specify each implementation. I want to configure a convention here.

lundi 24 avril 2017

Understanding Properties

As by definition of properties in C# , these are the extension of fields and can be get set. So can we set the properties of an object of a class as well?

class c1{
     public C2 obj {get;set;}
}

dimanche 23 avril 2017

Creating SMS Gateway using asp.net MVC

I m trying to implement my own SMS gateway using asp.net MVC. Please suggest any solution how to start with it.

Thanks in Advance!!

Post form always returning null

I have an application in asp .net mvc 4 as follows:

1.ProductsController.cs

namespace MvcApplication2.Controllers
{
    public class ProductsController : Controller
    {
        //
        // GET: /Products/

        [HttpGet]
        public ActionResult Products()
        {
            List<Product> prList = new List<Product>();
            Product p1 = new Product();
            p1.ProductName = "J & J";
            p1.Price = 40;
            p1.Ratings = 5;
            prList.Add(p1);
            Product p2 =  new Product();
            p2.ProductName = "Himalaya";
            p2.Price = 20;
            p2.Ratings = 2;
            prList.Add(p2);
            return View(prList);

        }

        [HttpPost]
        public ActionResult Products(FormCollection prList,List<MvcApplication2.Models.Product> fg) 
        {
            return View(prList);
        }

    }
}

2. ProductList.cs

namespace MvcApplication2.Models
{


    public class Product
    {
        public string ProductName { get; set; }
        public int Price { get; set; }
        public int Ratings { get; set; }
    }

}

3. Products.cshtml

@{
    Layout = null;

}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Products</title>
    @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")

    <script src="~/Scripts/jquery-3.2.1.min.js"></script>
</head>
@model IEnumerable<MvcApplication2.Models.Product>
@using (@Html.BeginForm("Products", "Products", FormMethod.Post))
{
<body>
    <div style="width:100%;height:100%;position: relative ">
        <div style="width:100%;top:0px;height:40px;position:relative;background-color:purple">
            <input type="submit" value="Sort price" style="float : right;width:30px;" id="SearchId" />
            @Html.TextBox("Search Box", null, new { @style = "float:right;width:80px "});
            <input type="submit" value="submit" />  
        </div>
        <div id="tableDiv">
            <table id="tableId">
                <tr>
                    <th>Name</th>
                    <th>Price in Rs.</th>
                    <th>Ratings</th>
                </tr>
@foreach (var drawing in Model)
{

                <tr>
                    <td>@drawing.ProductName</td>
                    <td>@drawing.Price</td>
                    <td>@drawing.Ratings</td>
                </tr>

}
            </table>
        </div>
    </div>
</body>
}
</html>

Whenever I navigate to http://localhost:5858/Products/Products and click and on submit , the contol comes to [HttpPost] in Products methods, but the model is always empty .

What is it that I am missing here?I am expecting the same model to be returned when the page was loaded , why is it that the model is becoming empty?

jeudi 20 avril 2017

Why does this one DropDownListFor work, and this other one doesnt?

I am trying to learn mvc, and after much struggle I finally got a DropDownListFor to work as intented. Here is the working Dropdownlistfor.

Working ViewModel

public partial class get_preKschedule_Result
    {
        public string start_time { get; set; }
        public Nullable<short> lunch_minutes { get; set; }
        public string dismiss_time { get; set; }
        public Nullable<short> headct { get; set; }
        public byte format { get; set; }
        public Nullable<byte> days_per_week { get; set; }
        public string description { get; set; }
    }

format is the type of preK program the school is enrolled in. The values are stored 1-10 in the database so the DropDownListFor will need all values and text. Here is the View.

Working View

@model  DirectoryMVC.Models.get_preKschedule_Result

@{
    List<SelectListItem> listItems = new List<SelectListItem>();
    listItems.Add(new SelectListItem { Text = "Head Start", Value = "6" });
    listItems.Add(new SelectListItem { Text = "Four Year Old At Risk", Value = "7" });
    listItems.Add(new SelectListItem { Text = "Integrated Special Ed", Value = "8" });
    listItems.Add(new SelectListItem { Text = "Reverse Mainstream Special Ed", Value = "9" });
    listItems.Add(new SelectListItem { Text = "All Other District Special Ed", Value = "10" });

}
<div class="col-md-2">
    @Html.DropDownListFor(m => m.format, new SelectList(listItems, "Value", "Text", listItems.Where(x => x.Value == Model.format.ToString())))
    @*listItems*@
</div>

I don't know if there is an easier way, but this is the way I finally got it to work. So when I do this exact same process for this next ViewModel it didn't work! Edit The administrator dropdown for title is not selecting any value, or setting any text. I will also list everything I tried. I am 100 percent sure that the data returned is correct I have verified in the watch that the models property title evaluates to true when I compare it to SelectListItems value.

Non-Working ViewModel

public partial class get_administrators_Result
{
    public int admin_id { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string title { get; set; }
    public string email { get; set; }
}

Non-Working View

@model  DirectoryMVC.Models.get_administrators_Result

@{ 
    List<SelectListItem> listItems = new List<SelectListItem>();
    listItems.Add(new SelectListItem { Text = "Mr.", Value = "Mr." });
    listItems.Add(new SelectListItem { Text = "Ms.", Value = "Ms." });
    listItems.Add(new SelectListItem { Text = "Dr.", Value = "Dr." });
    listItems.Add(new SelectListItem { Text = "Miss", Value = "Miss" });
    listItems.Add(new SelectListItem { Text = "Mrs.", Value = "Mrs." });
    listItems.Add(new SelectListItem { Text = "Rev.", Value = "Rev." });
}

<div class="col-md-1"> @Html.DropDownListFor(m => m.title, new SelectList(listItems, "Value", "Text", listItems.Where(x=>x.Value == Model.title)))
</div>

I have even tried

@Html.DropDownListFor(m => m.title, new SelectList(listItems, "Value", "Text", Model.title))
@Html.DropDownListFor(m => m.title, new SelectList(listItems, "Value", "Text", (object)Model.title))

and every other combination I can think of with the lambda (m=> m, ...

mardi 18 avril 2017

how to pass model to partialview in umbraco?

I want to pass a object as model to a partial view in umbraco. there is two function @Html.Partial() and @Html.Partial() which have 4 override method listed below :

@Html.Partial(string partialName)
@Html.Partial(string partialName, Object object)
@Html.Partial(string partialName, Object object, ViewDataDictionary dic)
@Html.Partial(string partialName, ViewDataDictionary dic)

and :

@Html.RenderPartial(string partialName)
@Html.RenderPartial(string partialName, Object object)
@Html.RenderPartial(string partialName, Object object, ViewDataDictionary dic)
@Html.RenderPartial(string partialName, ViewDataDictionary dic)

I try to use @Html.RenderPartial(string partialName, Object object) and @Html.Partial(string partialName, Object object) but i an getting this Exception:

Cannot bind source type <>f__AnonymousType0`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to model type Umbraco.Web.Models.RenderModel.

I search a lot in google to an example of using these methods but i cannot find any thing. so there are two question:

  1. What is different between Partial and RenderPartial method?
  2. How can I pass data to partialview from page razor?

How to remove the "" part from mvc

An mvc application I'm supposed to maintain doesn't work on FF.I have a site, which shows a pdf inside an <iframe>. When I try run it on FF, it shows me the Corrupted Content Error inside the iframe. The page you are trying to view cannot be shown because an error in the data transmission was detected . After googling a bit it seems it is due to having to many headers inside, so I checked in IE (it works properly on IE), and yeah, this was the frame content:

<object width="100%" height="100%" classid="clsid:......">
    <PARAM NAME="ExtentX" VALUE="25135">
    .... many other PARAM NAMEs>
</object>
<html style="display: none;">
  <head></head>
  <body></body>
</html>

So it appears to solve my problem I have to delete the <head> elements inside the fame. According to my googling it seems the problem is somewhere with the Response.appendHeader functions, but everything seems okay to me. My controller code:

Response.AddHeader("Content-Disposition", "inline; filename=" + fileName + "#toolbar=1&amp;view=FitV");
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

Someone suggested adding those lines before those lines, but it didn't help:

Response.ClearHeaders();
Response.ClearContent();
Response.Clear();