|
What you need to do is create jquery change event on the country ddl and pass the country Id to controller and update the states ddl with the results filtered by the country id selected.
Do the same for state and cities too.
I can see some code for states SelectStates() but don't know where you have used it.
|
|
|
|
|
This is for my new program written in MVC, in which I'm using lots avatars to represent things like users and items.
In my old program code in VB, I picked up the image from the disk drive, make a new canvas and wrote the image on the new canvas centering it back to the drive.
In this program, I got slick and took the bytes[] from file upload, and then I feed them into this function that returns the image back to me in various formats such as bytes[]. The program works, but I just can't get the new resized image to center on the canvas, it always starts on the left edge. The height is correct, but I get a black strip on the right side because it's smaller.
I'm not looking for someone to write code for me, just take a look at the function and perhaps you can see where I blew it and made a mistake. Perhaps its the order of graphic objects, maybe I have it backwards.
<pre lang="text"> Your codeblocks should be of the form
```C#
public static model_image_object avatar_resize(string pName, byte[] pBytes)
{
const int t_Width = 250;
const int t_Height = 250;
int cHeight = 0;
int cWidth = 0;
model_image_object pResult = new model_image_object();
MemoryStream stream_out = new MemoryStream();
using (Stream stream_in = new MemoryStream(pBytes))
{
Image image_in = Image.FromStream(stream_in);
int oWidth = image_in.Width;
int oHeight = image_in.Height;
Color bgColor = Color.FromArgb(255, 255, 255);
using (Bitmap bitmapObj = new Bitmap(t_Width, t_Height, PixelFormat.Format24bppRgb))
{
using (Graphics graphicObj = Graphics.FromImage(bitmapObj))
{
graphicObj.Clear(Color.Transparent);
graphicObj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
graphicObj.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
if (oWidth == oHeight)
{
cWidth = 250;
cHeight = 250;
}
else if (oWidth > t_Width)
{
cWidth = t_Width;
cHeight = (int)Math.Round((oHeight / (float)oWidth) * t_Width);
}
else if (oWidth < t_Width)
{
cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
cHeight = (int)Math.Round((oHeight / (float)oWidth) * cWidth);
}
else if (oHeight > t_Height)
{
cHeight = t_Height;
cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
}
int x = (cWidth - t_Width) / 2;
int y = (cHeight - t_Height) / 2;
graphicObj.DrawImage(image_in, x, y, t_Width, t_Height);
graphicObj.Save();
}
bitmapObj.Save(stream_out, ImageFormat.Png);
}
}
pResult.Data = stream_out.ToArray();
pResult.Name = pName;
pResult.Type = "image/png";
pResult.Size = new model_image_type_size();
pResult.Size.Height = cHeight;
pResult.Size.Width = cWidth;
return pResult;
}
```
public class model_image_object
{
public string Name { get; set; }
public string Type { get; set; }
public byte[] Data { get; set; }
public model_image_type_size Size { get; set; }
}
|
|
|
|
|
How about something like this:
if (oWidth <= t_Width && oHeight <= t_Height)
{
cWidth = oWidth;
cHeight = oHeight;
}
else if (oHeight < oWidth)
{
cWidth = t_Width;
cHeight = (int)Math.Round((oHeight / (float)oWidth) * t_Width);
}
else
{
cHeight = t_Height;
cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
}
int x = (t_Width - cWidth) / 2;
int y = (t_Height - cHeight) / 2;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well I've been working on this all morning. And your right, it was my calculation and I did get the Graphics and Bitmap objects right.
So after hours of using my calculator and confirming formulas, I had nothing. Then I decided to search for the same formula but written better and came across this. I looked at it and deemed it to be highly optimized already.
Well at least I got the thought right about canvas, ratios, positions, for the code just slid right into my code.
Thanks Richard, it was head scratcher. But I went with this instead.
On the positive side, I must admit that this function is pretty slick now that it works correctly.
Working with images as byte arrays is pretty cool for storing them in the database and writing them as files for HTTP calls.
On the negative side, working with numbers in c# is much different that VB. C# doesn't divide integers, didn't know that.
graphicObj.Clear(Color.Transparent);
graphicObj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
graphicObj.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
double ratioX = (double)canvasWidth / (double)originalWidth;
double ratioY = (double)canvasHeight / (double)originalHeight;
double ratio = ratioX < ratioY ? ratioX : ratioY;
int newHeight = Convert.ToInt32(originalHeight * ratio);
int newWidth = Convert.ToInt32(originalWidth * ratio);
int posX = Convert.ToInt32((canvasWidth - (originalWidth * ratio)) / 2);
int posY = Convert.ToInt32((canvasHeight - (originalHeight * ratio)) / 2);
graphicObj.Clear(Color.White);
graphicObj.DrawImage(image_in, posX, posY, newWidth, newHeight);
graphicObj.Save();
credit goes to
User egrunin - Stack Overflow[^]
|
|
|
|
|
when im trying this code in MVC4 Getting an error..
The name 'ObjectFactory' does not exist in the current context
using eManager.Domain;
using eManager.Web.Infrastructure;
using StructureMap;
namespace eManager.Web {
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
x.For<idepartmentdatasource>().HttpContextScoped().Use<departmentdb>();
});
return ObjectFactory.Container;
}
}
|
|
|
|
|
Just going out on a limb here, but I think you may have a "public class ObjectFactory" instead of a "public static class ObjectFactory".
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
Are you using ObjectFactory from StructureMap?
|
|
|
|
|
|
were you missing StructureMap reference? how did you resolve it?
|
|
|
|
|
I have a one data grid that returns datasets with different headings depending on the selection by the user.
I have search online in CodeProject but could not find a similar solution. Most had hard coding for the headings.
Please advise with examples on how to freeze heading
I am using .Net 4.5 with Microsoft Visual Studio Professional 2013.
This datagrid was developed in .Net 1.1 and migrated to .Net 4.5.
|
|
|
|
|
I am new in MVC. I have some views where there is no need of controller they are static views just some information to be displayed. i searched the web and found (View Without Controller Action in MVC[^]. My controller look like
public class PublicController : Controller
{
protected override void HandleUnknownAction(string actionName)
{
try
{
View(actionName).ExecuteResult(this.ControllerContext);
}
catch (Exception e)
{
Response.Write("PageNotFound");
}
}
}
i added an entry in routeconfig file as
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "NoAction",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Public", action = "HandleUnknownAction", id = UrlParameter.Optional }
);
}
and i am calling the view from me menu in my master file as
<ul>
<li><a href="@Url.RouteUrl("Public", new { name = "History.cshtml" })">History</a></li>
My history.cshtml file is inside "Public" folder and my controller name is PublicController, i also have pagenotfound.cshtml file which is also in public folder but it always shows me PageNotFound.cshtml file. I dont know how to call my view from my menu. Please help Thanks
|
|
|
|
|
The correct syntax for @Url.RouteUrl is
Url.RouteUrl("LinkName", new { controller = "ControllerName", action = "MethodName" })
You need to have a method in your controller matching your view. This is by design from MVC. If you have something inside another folder , then it has to match your controller.
I would recommend you read the concept of MVC before writing this code.
You may also use Areas for folder. Learn areas in MVC too.
|
|
|
|
|
I am adding html templates to actionmethods in views.and i have added JS folder,CSS folder.in route config file i have set index as main page.only for mainpage Jquery and css is applying but remaining pages it is not applying.if i changed route config file with another index2 css is applying on Index2.can you please tell me what are ways to solve this?
|
|
|
|
|
|
|
when I'm trying any one of these Getting Error ..pls help
public ActionResult Index()
{
/* Mapper.CreateMap();
var dbContext = new WorkTraningEntities();
var emplist = from employee in dbContext.Employees select employee;
var emps = new List();
if (emplist.Any())
{
foreach (var employee in emplist)
{
EmpEntity empModel = Mapper.Map(employee);
emps.Add(empModel);
}
}
return View(emps);*/
var config = new MapperConfiguration(cfg => cfg.CreateMap<Employee,EmpEntity>());
IMapper mapper = config.CreateMapper();
var source = new Employee();
var dest = mapper.Map<Employee,EmpEntity>(source);
Mapper.AssertConfigurationIsValid();
return View(source);
}
Error is :
The model item passed into the dictionary is of type 'MvcAutoMapperDemo.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcAutoMapperDemo.Employee]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'MvcAutoMapperDemo.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcAutoMapperDemo.Employee]'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The model item passed into the dictionary is of type 'MvcAutoMapperDemo.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MvcAutoMapperDemo.Employee]'.]
System.Web.Mvc.ViewDataDictionary1.SetModel(Object value) +608383
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +371
System.Web.Mvc.WebViewPage1.SetViewData(ViewDataDictionary viewData) +50
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +98
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +15
System.Web.Mvc.<>c__DisplayClass1a.<invokeactionresultwithfilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.b__19() +25
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +175
System.Web.Mvc.Async.<>c__DisplayClass2a.<begininvokeaction>b__20() +89
System.Web.Mvc.Async.<>c__DisplayClass25.<begininvokeaction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult1.End() +58
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +44
System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +16
System.Web.Mvc.Async.WrappedAsyncResult1.End() +58
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +54
System.Web.Mvc.Async.<>c__DisplayClass4.<makevoiddelegate>b__3(IAsyncResult ar) +16
System.Web.Mvc.Async.WrappedAsyncResult1.End() +58
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +12
System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +16
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9734909
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1532.0
|
|
|
|
|
The error is self-explatory. Your view expects a list of Employee objects so it will be something like
@model IEnumerable<Employee>
yet you are passing only a single Employee object. We can't tell you how to resolve this as we don't know your business rules. If your view caters for multiple employees but you only want to pass one employee then change the action to something like
return View(New List<Employee>{source});
|
|
|
|
|
As the error suggests , you are passing Employee Entity whereas it expects IEnumerable.
|
|
|
|
|
2 partial views connect to index view but first partial view have display data(name,datein,compliant where status = "new") and the submit button.once click the submit button (the status value changed to "Received")refresh the page and display the same data(name,datein,compliant)
if u have any examples related this can u plz send me or guide me if u have any idea.thankyou all who r helping me.
|
|
|
|
|
You have already posted this question, received an answer, and accepted the answer:
In MVC how two partial view connect to indexview[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The partial view just needs a form around the submit button etc whose action points to the action that generated the parent view and whose method is post. Submitting the form then posts the data to that action which will process it and return the view as normal.
This is all incredibly basic MVC stuff, you'd be best going through a book on MVC to learn the basics and how to do these things will become clear.
|
|
|
|
|
use of select command to fetch(Resume) Record into table
|
|
|
|
|
|
Not clear. what you exactly want ?
|
|
|
|